`

Ubuntu下安装selenium、pytester、tesseract

 
阅读更多

0. Ubuntu 14.10已经安装了Python2.7,所以无需额外安装python了

 

1. 安装pip:sudo apt-get install python-pip

 

2. 安装selenium:sudo pip install -U selenium

 

3. 验证是否安装成功:

        a. 打开终端,打开python命令行

        b. from selenium import webdriver

        c. driver = webdriver.Firefox(); driver.get("http://www.baidu.com")

        d. 此时应该打开Firefox浏览器,并打开百度的主页面

 

4. pytester、tesseract

a. 安装所需的库
sudo apt-get install libpng12-dev
sudo apt-get install libjpeg62-dev
sudo apt-get install libtiff5-dev
sudo apt-get install gcc
sudo apt-get install g++
sudo apt-get install automake

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

c. 所以要先下载安装leptonica,http://www.leptonica.org/download.html 或者http://code.google.com/p/leptonica/downloads/list最新的是leptonica-1.71.tar.gz

d. 下载安装tesseract,http://code.google.com/p/tesseract-ocr/,
最新的是 tesseract-ocr-3.02.02.tar.gz

e. 安装leptonica和tesseract
./configure
make -j4
sudo make install

f. 下载安装 tesseract 的语言数据包,http://code.google.com/p/tesseract-ocr/downloads/list,最新的是 tesseract-ocr-3.02.eng.tar.gz,
解压tessdata目录下的文件(9个)到 "/usr/local/share/tessdata"目录下

g. 下载安装 pytesser,http://code.google.com/p/pytesser/,
最新的是 pytesser_v0.0.1.zip,直接解压就能使用

 

 

 5. 测试pytesser,到pytesser的安装目录,创建一个test.py,python test.py 查看结果,tesseract 目录还有其他tif文件,也可以复制过来测试,上面测试的tif,png文件正确识别出文字。

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

 

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

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

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

 

7. 错误记录:

a. 遇到这个错误:

$ 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

b. tesseract安装成功的提示:
www@Kylin:~/code/python/pytesser$ 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

 

8. 需要自己下载的软件包都在附件中,其中tesseract-ocr-3.02.eng.zip有12M,超出了iteye附件不超过10M的规定,所以没有上传。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics