python的验证码识别.md
2015-11-23 14:40
621 查看
1. 三个文件:
pytesseractPIL
tesseract
上面两个直接pip,核心部件tessract是一个exe包,大概是是pytesseract调用tesseract,再通过PIL库对验证码进行识别。
2. bug修复
网上很多人的博客都讲述了基于pytesseract来对验证码的识别,但是按照他们的方法运行,却会报如下错Traceback (most recent call last):
File “**.py”, line , in
vcode = pytesseract.image_to_string(image)
File “C:\Python27\lib\site-packages\pytesseract\pytesseract.py”, line 143, in image_to_string
if len(image.split()) == 4:
File “C:\Python27\lib\site-packages\PIL\Image.py”, line 1497, in split
if self.im.bands == 1:
AttributeError: ‘NoneType’ object has no attribute ‘bands’
问题应该出现在pytesseract.py的143和Image.py的1497行。进Python27\Lib\site-packages\PIL,将split函数换成如下
def split(self): "Split image into bands" self.load() if self.im.bands == 1: ims = [self.copy()] else: ims = [] #self.load() for i in range(self.im.bands): ims.append(self._new(self.im.getband(i))) return tuple(ims)
这样就应该好了。问题应该是self.load()这个函数出错了,注释掉即可。
3. demo
#coding:utf-8 import requests from PIL import Image import pytesseract import cStringIO code_url = 'http://self.nwpu.edu.cn:8080/selfservice/common/web/verifycode.jsp' file = cStringIO.StringIO(requests.get(code_url).content) image = Image.open(file) print pytesseract.image_to_string(image)
运行结果:4070
如demo,可以将http://self.nwpu.edu.cn:8080/selfservice/common/web/verifycode.jsp 的验证码识别
4. 参考资料
http://blog.bear2.cn/http://range.pw/?p=16
相关文章推荐
- python 的expect,paramiko ssh交互使用
- LeetCode OJ 系列之217 Contains Duplicate --Python
- python 编码问题(转载)
- isalnum()和isalpha()
- 恶补
- python发送邮件
- python 学习小结(1)
- 【Python】django权限管理
- python帮助信息查看以及笔记
- Python基础之【第四篇】
- python codeforces 322 div2 C
- Python问题汇总
- PYTHON之全局变量
- Python如何使用tfidf
- [LeetCode]题解(python):060-Permutation Sequence
- [LeetCode]题解(python):059-Spiral Matrix II
- python 里关于字符的处理
- python 开发中易混淆点
- [LeetCode]题解(python):058-Length of Last Word
- python实现爬虫统计学校BBS男女比例(三)数据处理