![](/img/trans.png)
[英]Pytesser in Python 2.7.9 - print image_to_string(image) error
[英]Python error when importing image_to_string from tesseract
我最近使用了tesseract OCR和python,当我尝试从tesseract导入image_to_string
时,我一直收到错误。
导致问题的代码:
# Perform OCR using tesseract-ocr library
from tesseract import image_to_string
image = Image.open('input-NEAREST.tif')
print image_to_string(image)
上述代码导致的错误:
Traceback (most recent call last):
file "./captcha.py", line 52, in <module>
from tesseract import image_to_string
ImportError: cannot import name image_to_string
我已经确认安装了tesseract模块:
digital_alchemy@roaming-gnome /home $ pydoc modules | grep 'tesseract'
Hdf5StubImagePlugin _tesseract gzip sipconfig
ORBit cairo mako tesseract
我相信我已经抓住了所有必需的套餐,但不幸的是我只是陷入了困境。 看来该功能不在模块中。
任何帮助非常感谢。
似乎对我有用的另一种可能性是修改pytesseract,而不是从PIL导入Image导入Image
修改pytesseract后在PyCharm中有效的代码:
from pytesseract import image_to_string
from PIL import Image
im = Image.open(r'C:\Users\<user>\Downloads\dashboard-test.jpeg')
print(im)
print(image_to_string(im))
Pytesseract我通过PyCharm内置的包管理安装
您的语法对于已安装的模块是否正确? 这image_to_string
功能看起来是每使用例如PyTesser此页上: https://code.google.com/p/pytesser/
您的导入类似于python-tesseract,其中列出了一个更复杂的用法示例: https : //code.google.com/p/python-tesseract/
对于Windows遵循以下步骤
pip3 install pytesseract
pip3 install pillow
安装tessaract-ocr也是必需的https://github.com/tesseract-ocr/tesseract/wiki否则你会收到一个错误Tessract不在路径上
Python代码
from PIL import Image
from pytesseract import image_to_string
print ( image_to_string(Image.open('test.tif'),lang='eng') )
什么对我有用:
在我安装pytesseract表单tesseract-ocr-setup-3.05.02-20180621.exe后,我添加了行pytesseract.pytesseract.tesseract_cmd="C:\\\\Program Files (x86)\\\\Tesseract-OCR\\\\tesseract.exe"
并使用上面的代码形式这是所有代码:
import pytesseract
from PIL import Image
pytesseract.pytesseract.tesseract_cmd="C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe"
im=Image.open("C:\\Users\\<user>\\Desktop\\ro\\capt.png")
print(pytesseract.image_to_string(im,lang='eng'))
我使用的是带有PyCharm Community Edition 2018.2.3 x64的Windows 10
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.