1、环境:
系统:XP
Python版本:2.7.5
2、所需文件:
(1)、pillow地址:https://pypi.python.org/pypi/Pillow/
(2)、tesseract地址:https://github.com/tesseract-ocr
(3)、pytesser地址:https://code.google.com/p/pytesser/
3、安装
(1)、pillow和tesseract直接双击安装,没什么值得注意的。
(2)、pytesser无需安装,解压到某个文件夹,让后添加环境变量(PYTHONPATH)。比如walker的PYTHONPATH环境变量值是 C:\Python27\Lib\site-packages\pytesser_v0.0.1
注意:将pytesser_v0.0.1目录下pytesser.py第6行的import Image改为from PIL import Image
4、测试
其中图片:
5、可以看到,识别并不是很精确。可以将得到的字符串转为大写,取出可能的字符,比如上面的验证码可能的字符集为 大写字母和数字,将两个字符串的大写字母和数字取出来是可以得到正确验证码的。
6、如果发现彩色图片不能识别,可以先将其转换为黑白图片再识别。(PIL模式介绍)
1
2
3
4
5
|
from
PIL
import
Image
image
=
Image.
open
(r
'D:\tmp\in.jpg'
)
image
=
image.convert(
"1"
)
#转换成黑白图片
image.save(r
'D:\tmp\out.jpg'
)
|
推荐阅读:
3、Python图像处理库PIL的基本概念介绍。(pillow.readthedocs.io、pillow-zh-cn.readthedocs.io)
*** walker * 2014-01-20 ***
本文转自walker snapshot博客51CTO博客,原文链接http://blog.51cto.com/walkerqt/1353180如需转载请自行联系原作者
RQSLT