码迷,mamicode.com
首页 > 其他好文 > 详细

Tesseract pytesseract的安装和使用

时间:2017-02-07 12:26:50      阅读:5985      评论:0      收藏:0      [点我收藏+]

标签:windows   tesseract   pil   报错   registry   span   std   数据   files   

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,并且可以在命令行里可以使用。

Tesseract pytesseract的安装和使用

标签:windows   tesseract   pil   报错   registry   span   std   数据   files   

原文地址:http://www.cnblogs.com/lilongsy/p/6373439.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!