我正在尝试开始使用 pytesseract,但正如你在下面看到的,我遇到了问题。
我发现人们遇到了似乎相同的错误,他们说这是 PIL 1.1.7 中的错误。其他人说这个问题是由于 PIL 懒惰造成的,需要强制 PIL 加载图像im.load()
打开后,但这似乎没有帮助。任何建议都非常感激。
K:\Glamdring\Projects\Images\OCR>python
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> import pytesseract
>>> pytesseract.image_to_string(Image.open('foo.png'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build\bdist.win32\egg\pytesseract\pytesseract.py", line 143, in image_to_string
File "c:\Python27_32\lib\site-packages\PIL\Image.py", line 1497, in split
if self.im.bands == 1:
AttributeError: 'NoneType' object has no attribute 'bands'
尝试分别使用 Image 和 pytesseract 模块中的对象。
它解决了我的问题:
try:
import Image
except ImportError:
from PIL import Image
import pytesseract
img = Image.open('myImage.jpg')
img.load()
i = pytesseract.image_to_string(img)
print i
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)