python处理识别图片验证码

安装图片图像处理标准库PIL
图片处理示例:
1 from PIL import Image
2 from pytesser import *
3 image = Image.open('7039.jpg')
4 print image_file_to_string('7039.jpg')
5 print image_to_string(image)

 

备注:如果出现报错ImportError: The _imaging C module is not installed,可能出现的原因下载错了版本,更改下安装64位的版本

图片识别

pytesser是谷歌OCR开源项目的一个模块,在python中导入这个模块即可将图片中的文字转换成文本,但是在pytesser模块中调用了tesseract,所以需要先安装tesseract

tesseract下载路径:https://bitbucket.org/3togo/python-tesseract/downloads/,选择合适的版本进行下载安装

  • pytesser安装
    • 下载路径:http://code.google.com/p/pytesser/ ,下载下来的模块包并不是传统的安装包,所以需要进行一系列的设置
    • 解压文件夹,新建一个空的__init.py__文件
    • 下载Tesseract OCR engine:http://code.google.com/p/tesseract-ocr/,解压后,将文件中的tessdata文件夹,复制至ptesser中进行替换原文件
    • 复制pytesser至python安装目录的Libsite-packages,并且添加至环境变量中(如果觉得这一系列操作复杂可以直接将源码放到代码路径)

图片识别源码

1 from PIL import Image
2 from pytesser import *
3 image = Image.open('7039.jpg')
4 print image_file_to_string('7039.jpg')
5 print image_to_string(image)

 

文件示例 7039.jpg

可能遇到的问题及解决方案:

  1. raise IOError("cannot identify image file"),将脚本中的import Image改为from PIL import Image
  2. 将pytesser.py中的import Image改为from PIL import Image

转载于:https://www.cnblogs.com/Hawthorn-Garden/p/8491816.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值