环境准备
PIL
tesseract-ocr
pytesseract模块
pillow
错误1:from . import VERSION, PILLOW_VERSION, _plugins
错误的指向是Image.py 具体原因还没分析出来,最后卸载了上述所有的包后,再参照了https://www.cnblogs.com/hupeng1234/p/7136442.html这个安装顺序进行了安装(pillow在pip install pytesseract的时候会自动安装)
错误2:'NoneType' object has no attribute 'bands',参照了http://blog.csdn.net/ghost0620/article/details/50974958 说可能是image库的一个bug,具体修改如下。
错误3:WindowsError: [Error 2]
扫描二维码关注公众号,回复:
3288804 查看本文章
上网找解决方法,说是pytesseract.py 里面的
tesseract_cmd = 'tesseract' 改成 tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe' 路径前面加r防止转义。最后试试运行代码
import pytesseract
import Image
a = Image.open('d:\yan1.png')
vcode = pytesseract.image_to_string(a)
print vcode
从网上下载的一个比较模糊的图片进行识别,返回的是空,后来自己手写了几个数字保存为图片后,可以识别出来。感觉这个库的识别成功率不是很高。