本文介绍了pytesseract为什么引起AttributeError:'NoneType'对象没有属性'bands'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开始使用pytesseract,但是正如您在下面看到的那样,我遇到了问题.

I am trying to get started using pytesseract but as you can see below I am having problems.

我发现人们发现了似乎相同的错误,他们说这是PIL 1.1.7中的错误.其他人说,问题是由于PIL懒惰引起的,需要在打开后强制PIL用im.load()加载图像,但这似乎无济于事.感谢收到任何建议.

I have found people getting what seems to be the same error and they say that it is a bug in PIL 1.1.7. Others say the problem is caused by PIL being lazy and one needs to force PIL to load the image with im.load() after opening it, but that didn't seem to help. Any suggestions gratefully received.

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 to use objects from Image and pytesseract module separately.
It solved my problem:

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

这篇关于pytesseract为什么引起AttributeError:'NoneType'对象没有属性'bands'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 14:18