Python验证码通过pytesser识别


Python安装包:

需要安装的包主要有两个: PIL 和 pytesser 、tesseract

(1)、安装PIL:下载地址:http://www.pythonware.com/products/pil/

下载后是一个exe程序,直接双击安装

(2)、pytesser:下载地址:http://code.google.com/p/pytesser/

pytesser 模块的安装:

下载后得到 “pytesser.zip”,是一个压缩文件,使用方法: 

1、在 “C:\Python27\Lib\site-packages” 路径下新建一个文件夹,命名 “pytesser” 。把 “pytesser.zip” 里的文件解压到该目录:

2、将 “pytesser.py” 改名为 “__init__.py”。

3、打开 “__init__.py” 文件,修改:tesseract_exe_name = 'C:\\Python27\\Lib\\site-packages\\pytesser\\tesseract' # Name of executable to be called at command line

4、pytesser 模块依赖于 PIL 模块,如果是按照上面的方法安装 PIL 的话,需要把 “init.py” 文件里的 “import Image” 改成 “from PIL import Image” 。

下载解压后直接放C:\Python27\Lib\site-packages,同时,新建一个pytesser.pth,内容就写,注意这里的内容一定要和pytesser这个文件夹同名,意思就是pytesser文件夹,pytesser.pth,及内容都要一样!

(3)、Tesseract OCR engine下载:http://code.google.com/p/tesseract-ocr/

下载后解压,tessdata文件夹,用其替换掉pytesser解压后的tessdata文件夹即可。(就上面的pytesser文件夹)

代码如下:

1 #-*- coding:utf-8 -*-
2 __author__ = "carry"
3 from PIL import Image
4 from pytesser import *
5 
6 image = Image.open('xx.jpg')
7 print image_to_string(image)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM