我正在运行Python2.6.6,希望安装pytesseract包。在提取和安装之后,我可以从命令行调用pytesseract。不过,我想在python中运行tesseract。我有以下代码(ocr.py):
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'))
当我使用python 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和test-european.jpg位于工作目录中。有人能帮我运行这个代码吗? 我试过以下方法:
任何帮助都是感激的,因为我正在努力解决这个问题几个小时了。
tesseract_cmd
应该指向命令行程序^{pytesseract
。例如,在Ubuntu上,可以使用以下命令安装程序:
然后将变量设置为
tesseract
或/usr/bin/tesseract
。相关问题 更多 >
编程相关推荐