博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用pytesseract识别简单验证码
阅读量:6972 次
发布时间:2019-06-27

本文共 1688 字,大约阅读时间需要 5 分钟。

from PIL import Imageimport pytesseractfrom pytesseract import *rep={
'O':'0', #替换列表 'I':'1','L':'1', 'Z':'2', 'S':'8' };def initTable(threshold=140): # 二值化函数 table = [] for i in range(256): if i < threshold: table.append(0) else: table.append(1) return table#--------------------------------------------------------------------------------------im = Image.open('C:/Users/asus-pc/Desktop/Captcha.jpg') #1.打开图片im = im.convert('L') #2.将彩色图像转化为灰度图binaryImage = im.point(initTable(), '1') #3.降噪,图片二值化# binaryImage.show()text = image_to_string(binaryImage, config='-psm 7')#4.对于识别结果,常进行一些替换操作for r in rep: text = text.replace(r,rep[r])#5.打印识别结果print(text)复制代码

别人写的

from PIL import Imageimport pytesseractfrom pytesseract import *rep={
'O':'0', #替换列表 'I':'1','L':'1', 'Z':'2', 'S':'8' };def initTable(threshold=140): # 二值化函数 table = [] for i in range(256): if i < threshold: table.append(0) else: table.append(1) return table#--------------------------------------------------------------------------------------im = Image.open('C:/Users/asus-pc/Desktop/Captcha.jpg') #1.打开图片im = im.convert('L') #2.将彩色图像转化为灰度图binaryImage = im.point(initTable(), '1') #3.降噪,图片二值化# binaryImage.show()text = image_to_string(binaryImage, config='-psm 7')#4.对于识别结果,常进行一些替换操作for r in rep: text = text.replace(r,rep[r])#5.打印识别结果print(text)复制代码

转载于:https://juejin.im/post/5a32077b5188253d6817991c

你可能感兴趣的文章
py 的 第 24 天
查看>>
BZOJ 3456 城市规划
查看>>
多轨视频编辑技术支持
查看>>
who
查看>>
sql where 1=1
查看>>
HDU2425:Hiking Trip(BFS+优先队列)
查看>>
[Oracle]ORA-01461: can bind a LONG value only for insert into a LONG column
查看>>
xcode6新建工程
查看>>
单向路由算法
查看>>
RabbitMQ系列教程之二:工作队列(Work Queues)
查看>>
scrapy入门教程
查看>>
Linux学习之CentOS(三十三)--DNS基础及域名系统架构
查看>>
leetcode349
查看>>
批处理-自动同步数据库
查看>>
git常用命令[持续更新]
查看>>
HTML标签 — dl,dt,dd
查看>>
python-----基础大杂烩
查看>>
多个Tomcat同时运行环境配置 - imsoft.cnblogs
查看>>
计算概论(A)/基础编程练习2(8题)/6:数组逆序重放
查看>>
客户文章:Windows Azure SendGrid入门
查看>>