ubuntu 12.04 下安装 PyTesser 进行OCR识别

ubuntu 12.04 下安装 PyTesser 进行OCR识别

安装所需的库

复制代码
sudo apt-get install libpng12-dev
sudo apt-get install libjpeg62-dev
sudo apt-get install libtiff4-dev

sudo apt-get install gcc
sudo apt-get install g++
sudo apt-get install automake
复制代码

 

pytesser 调用了 tesseract,因此需要安装 tesseract,安装 tesseract 需要安装 leptonica,否则编译tesseract 的时候出现 "configure: error: leptonica not found"。

 

以下都是解压编译安装的老步骤:

./configure
make -j4
sudo make install

 

下载安装leptonica

http://www.leptonica.org/download.html 或者

http://code.google.com/p/leptonica/downloads/list

最新的是leptonica-1.69.tar.bz2

 

下载安装tesseract

http://code.google.com/p/tesseract-ocr/

最新的是 tesseract-ocr-3.02.02.tar.gz

 

下载安装 tesseract 的语言数据包

http://code.google.com/p/tesseract-ocr/downloads/list

最新的是 tesseract-ocr-3.01.eng.tar.gz

解压tessdata目录下的文件(9个)到 "/usr/local/share/tessdata"目录下

注意:这个网址下载到的只有一个,不能用,使用中会报错,http://tesseract-ocr.googlecode.com/files/eng.traineddata.gz

 

下载安装 pytesser

http://code.google.com/p/pytesser/

最新的是 pytesser_v0.0.1.zip 

 

测试pytesser

到pytesser的安装目录,创建一个test.py,python test.py 查看结果。

复制代码
from pytesser import *
#im = Image.open('fnord.tif')
#im = Image.open('phototest.tif')
#im = Image.open('eurotext.tif')
im = Image.open('fonts_test.png')
text = image_to_string(im)
print text
复制代码

tesseract 目录还有其他tif文件,也可以复制过来测试,上面测试的tif,png文件正确识别出文字。

 

pytesser的验证码识别能力较低,只能对规规矩矩不歪不斜数字和字母验证码进行识别。测试了几个网站的验证码,显示 Empty page,看来用它来识别验证码是无望了。

测试发现提高对比度后再识别有助于提高识别准确率。

enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance(4)

 http://www.cnblogs.com/congbo/archive/2012/10/31/2746943.html

参考:

http://www.oschina.net/question/54100_59400

http://ubuntuforums.org/showthread.php?p=10248384

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值