我正在運行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在工作目錄中。有人可以幫我運行這段代碼嗎? 我曾嘗試以下:
- 調整了tesseract_cmd爲「pytesseract」
- 安裝的Tesseract-OCR
因爲我想現在就解決這個問題了幾個小時的任何幫助表示讚賞。
'tesseract test.png stdout'工作嗎? – wrwrwr