您的位置:首页 > 编程语言 > Python开发

Python验证码通过pytesser识别

2017-07-23 00:01 253 查看

Python安装包:

需要安装的包主要有两个: PILpytessertesseract

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

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

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

[b]pytesser 模块的安装:[/b]

下载后得到 “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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: