本文实例讲述了Python编程实现的图片识别功能。分享给大家供大家参考,具体如下:
1. 安装PIL,官方没有WIN64位,Pillow替代
pip install Pillow-2.7.0-cp27-none-win_amd64.whl
2. 安装Pytesser
下载pytesser_v0.0.1.zip,解压后复制进Python27\Lib\site-packges\pytesser路径下,无pytesser则新建
在Python27\Lib\site-packges\pytesser中新建一pytesser.pth文件,内容为pytesser
在pytesser内,修改三点
① pytesser.py修改成__init.py__
② 修改pytesser.py
import Image
改为
from PIL import Image
tesseract_exe_name = 'tesseract' 改为tesseract_exe_name = 'Python27\\Lib\\site-packges\\pytesser\\tesseract' 注意\转义
③ 安装Tesseract
下载Tesseract OCR engine:http://code.google.com/p/tesseract-ocr/ ,
下载后解压,找到tessdata文件夹,用其替换掉pytesser解压后的tessdata文件夹即可。
不过除了测试用验证码之外,其余的系统验证码的识别率很低。
附测试代码
from pytesser import * from PIL import Image, ImageEnhance im = Image.open('D:\Python27\Lib\site-packages\pytesser\phototest.tif') im2 = Image.open(r'D:\Python27\Lib\site-packages\pytesser\fnord.tif','r') im3 = Image.open(r'F:\PROJECT\python\code\Study_1\src\20170424\cp.jpg','r') #文件读写模式以防报错 #图片处理1::黑白处理 enhancer = ImageEnhance.Contrast(im3) image2 = enhancer.enhance(5) image2.show() print image_to_string(image2) #图片处理2: 降噪处理 imgry = im3.convert('L') #灰度处理 #灰度处理基础上二值化处理 threshold = 140 table = [] for i in range(256): if i < threshold: table.append(0) else: table.append(1) out = imgry.point(table, '1') out.show() text = image_to_string(out) if text.isspace() : print "FAILE" else: print text #print text
更多关于Python相关内容感兴趣的读者可查看本站专题:《Python图片操作技巧总结》、《Python数据结构与算法教程》、《Python Socket编程技巧总结》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》
希望本文所述对大家Python程序设计有所帮助。
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 【原神】V5.0攻略 | 林尼攻略一图流
- 李翊君.1993-相思的烈酒【上华】【WAV+CUE】
- 古巨基.1998-LEO.KU(国)【千禧年代】【WAV+CUE】
- 郭子.2001-原来你什么都不想要创作集丫滚石】【WAV+CUE】
- 《使命召唤:黑色行动6》新预告公布!10月25日发售
- Atlus《暗喻幻想》媒体评分汇总:高分好评如潮!
- 2024金摇杆奖提名揭晓 《黑神话》角逐最佳视觉设计!
- 群星《新说唱2024 第3期 (上)》[320K/MP3][32.76MB]
- 群星《新说唱2024 第3期 (上)》[FLAC/分轨][95.38MB]
- 群星《新说唱2024 第3期 (下)》[320K/MP3][31.36MB]
- 幻兽帕鲁手游什么时候正式上线 最新消息一览
- 西普大陆BOSS位置盘点 解锁天启纪元玩法
- 西普大陆精灵进阶培养攻略 精灵养成指南
- dnf手游法控法系职业哪个强 dnf手游法控法系职业强度排行
- 魔兽世界血藤护目镜图纸在哪买 wlk血藤护目镜图纸购买位置介绍