我最近安装了Tesseract模块并找到了一些教程,但是我没有遇到互联网上的任何解决方案。这是简单的代码和错误:
from PIL import Image
from tesseract import image_to_string
a = Image.open('/Users/bob/Desktop/108.jpg')
b = image_to_string(a)
print(b)
Run Code Online (Sandbox Code Playgroud)
这是错误:
print 'Creating user config file: {}'.format(_config_file_usr)
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
这是图像:108.png
不要使用 from tesseract import image_to_string
做pip install pytesseract和import pytesseract
另外,请确保您在 .py 文件中分配了 .exe,如下所示:
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'
并且您的程序将需要从以下内容重新设计:
a = Image.open('/Users/bob/Desktop/108.jpg')
b = image_to_string(a)`
Run Code Online (Sandbox Code Playgroud)
到
text = pytesseract.image_to_string(Image.open('/Users/bob/Desktop/108.jpg'))
Run Code Online (Sandbox Code Playgroud)