2016-10-19 55 views
1

我正在運行python 2.6.6並且想要安裝pytesseract包。解壓縮和安裝後,我可以從命令行調用pytesseract。但是我想在Python中運行tesseract。我有以下代碼(ocr.py):在pytesseract運行示例代碼

try: 
    import Image 
except ImportError: 
    from PIL import Image 
import pytesseract 
print(pytesseract.image_to_string(Image.open('test.png'))) 
print(pytesseract.image_to_string(Image.open('test-european.jpg'),lang='fra')) 

當我運行由蟒蛇ocr.py的代碼,我得到以下輸出:

Traceback (most recent call last): 
    File "ocr.py", line 6, in <module> 
    print(pytesseract.image_to_string(Image.open('test.png'))) 
    File "/pytesseract-0.1.6/build/lib/pytesseract/pytesseract.py", line 164, in image_to_string 
    raise TesseractError(status, errors) 
pytesseract.TesseractError: (2, 'Usage: python tesseract.py [-l language] input_file') 

test.png和測試的歐洲。 jpg在工作目錄中。有人可以幫我運行這段代碼嗎? 我曾嘗試以下:

  1. 調整了tesseract_cmd爲「pytesseract」
  2. 安裝的Tesseract-OCR

因爲我想現在就解決這個問題了幾個小時的任何幫助表示讚賞。

+0

'tesseract test.png stdout'工作嗎? – wrwrwr

回答

1

tesseract_cmd應該指向命令行程序tesseract而不是pytesseract

例如在Ubuntu上,你可以使用安裝程序:

sudo apt install tesseract-ocr 

然後將變量設置爲只tesseract/usr/bin/tesseract

+0

感謝您的回答。在我的情況下,它在'/ usr/local/bin/tesseract' – user6046209

相關問題