ubuntu安装tesseract 进行OCR识别
sudo apt-get install libpng12-devsudo apt-get install libjpeg62-devsudo apt-get install libtiff4-devsudo apt-get install gccsudo apt-get install g++sudo apt-get install automake
?
pytesser 调用了 tesseract,因此需要安装 tesseract,安装 tesseract 需要安装?leptonica,否则编译tesseract 的时候出现 "configure: error: leptonica not found"。
?
以下都是解压编译安装的老步骤:
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)
?
错误记录1.遇到这个错误
$ tesseract foo.png bar
tesseract: error while loading shared libraries: libtesseract_api.so.3 cannot open shared object file: No such file or directory
?
You need to update the cache for the runtime linker. The following should get you up and running:
$ sudo ldconfig
?
2. 使用遇到如下错误
Tesseract Open Source OCR Engine v3.02.02 with LeptonicaError in findTiffCompression: function not presentError in pixReadStreamTiff: function not presentError in pixReadStream: tiff: no pix returnedError in pixRead: pix not readUnsupported image type.
坑爹居然是leptonica1.69的bug,参考:https://bugs.mageia.org/show_bug.cgi?id=10411#c4,坑爹的是居然没有找到组新修复版,不得已我使用leptonica-1.68,可以了。
?
安装成功的提示:
yunpeng@yunpeng-duitang:~/下载/tesseract-temp$ tesseract
Usage:tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfile...]
pagesegmode values are:
0 = Orientation and script detection (OSD) only.
1 = Automatic page segmentation with OSD.
2 = Automatic page segmentation, but no OSD, or OCR
3 = Fully automatic page segmentation, but no OSD. (Default)
4 = Assume a single column of text of variable sizes.
5 = Assume a single uniform block of vertically aligned text.
6 = Assume a single uniform block of text.
7 = Treat the image as a single text line.
8 = Treat the image as a single word.
9 = Treat the image as a single word in a circle.
10 = Treat the image as a single character.
-l lang and/or -psm pagesegmode must occur before anyconfigfile.
Single options:
? -v --version: version info
? --list-langs: list available languages for tesseract engine
?
参考:
http://www.oschina.net/question/54100_59400
http://ubuntuforums.org/showthread.php?p=10248384
?