pytesser图片文本识别

 

python图片文本识别使用的工具是PIL和pytesser。因为他们使用到很多的python库文件,为了避免一个个工具的安装,建议使用pythonxy,这个工具的介绍可参考baidu。
pytesser是谷歌OCR开源项目的一个模块,在Python中导入这个模块即可将图片中的文字转换成文本。pytesser调用了 tesseract。当在Python中调用pytesser模块时,pytesser又用tesseract识别图片中的文字。pytesser的使用 步骤如下:

首先,安装Python2.7版本,这个版本比较稳定,建议使用这个版本。
其次,安装pythoncv。
然后,安装PIL工具,下载的地址是:http://www.pythonware.com/products/pil/,pytesser的使用需要PIL库的支持。
接着下载pytesser,下载的地址是:http://code.google.com/p/pytesser/downloads/list
最后,将pytesser解压,这个是免安装的,可以将解压后的文件cut到Python安装目录的Libsite-packages下直接使用,比如我的安装目录是:C:Python27Libsite-packages,同时把这个目录添加到环境变量之中
完成以上步骤之后,就可以编写图片文本识别的Python脚本了。参考脚本如下:
from pytesser import *
import ImageEnhance
 
image = Image.open('D:\xiehao\workspace\python\5.png')
 
#使用ImageEnhance可以增强图片的识别率
enhancer = ImageEnhance.Contrast(image)
image_enhancer = enhancer.enhance(4)
 
print image_to_string(image_enhancer)
原文地址:https://www.cnblogs.com/timssd/p/4735132.html