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.oschina.net/question/54100_59400

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章