python-2.7 - 为什么 pytesseract 导致 AttributeError : 'NoneType' object has no attribute 'bands' ?

标签 python-2.7 python-imaging-library ocr

我正在尝试开始使用 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

关于python-2.7 - 为什么 pytesseract 导致 AttributeError : 'NoneType' object has no attribute 'bands' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32791563/

相关文章:

python-2.7 - 具有外部 Python 库的 Odoo 自定义模块

python-3.x - 如何安装适用于 Python 3.6 的 PIL/Pillow?

python - 检测图像中的水平线

javascript - 显示由 python pillow 模块生成的字节的图像

python - OCR 给出错误的输出

python - 来自 Google Vision API OCR 的响应 400,带有指定图像的 base64 字符串

python - 类型转换不适用于 08 和 09

python - 尝试使用 BeautifulSoup 从我的代码中使用 Xpath 进行网页抓取

Python 执行 SSH 登录并做一些事情

java - 编译此OCR库代码