Tesseract pytesseract的安装和使用

Tesseract是开源的OCR引擎,可以识别的图片里的文字,支持unicode(UTF-8)编码,100多种语言,需要下载相应语言的训练数据。

安装:

有两种方法,一种是通过编译源码,比较麻烦。我使用的是另外一种方法,在windows下,使用编译好的二进制文件。

安装文件下载地址:https://sourceforge.net/projects/tesseract-ocr-alt/files/

最新训练数据下载地址:https://github.com/tesseract-ocr/tessdata

建议使用稳定的3.0版本,我试用的4.0开发版报错。

注意选中Registry settings,也就是把Path和TESSDATA_PREFIX环境变量自动配置好。

如果要识别中文,就把中文训练数据选中。

 

使用:

安装完成之后,就可以在命令行下执行识别图片了。

命令行下执行:

  1 tesseract test.png stdout 

都可以识别。

但是识别中文或者是中英文混合的时候,识别率不高。

 

tesseract cs.png stdout -l eng+chi_sim

 

Python封装模块pytesseract:

tesseract有很多语言的封装包,这里只介绍下python的pytesseract。

源码地址:https://github.com/madmaze/pytesseract

可以直接使用pip安装:

pip install pytesseract

 

使用示例:

from PIL import Image
import pytesseract
print(pytesseract.image_to_string(Image.open('test.png')))
print(pytesseract.image_to_string(Image.open('test-european.jpg'), lang='fra'))

 

注意事项:

需要先安装好PIL和tesseract,并且可以在命令行里可以使用。

posted @ 2017-02-07 11:41  SubjectiveInitiative  阅读(3127)  评论(0编辑  收藏  举报