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

本文共 1636 字,大约阅读时间需要 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)复制代码

转载地址:http://onqwm.baihongyu.com/

你可能感兴趣的文章
ubuntu解压命令
查看>>
python3.x的print()函数默认参数
查看>>
嵌入式 Linux进程间通信(二)——exec族函数
查看>>
Oracle数据库精讲课程之Rac管理最全课程
查看>>
我的友情链接
查看>>
Spring学习总结(4)——Spring AOP教程
查看>>
Jenkins自动化构建(一)
查看>>
log4j配置详解
查看>>
我的友情链接
查看>>
面试100题之8
查看>>
一些以太网非核心功能的标准
查看>>
oracle EBS 克隆之数据库克隆
查看>>
【python2】commands模块getstatusoutput函数的小问题
查看>>
oracle常用sql
查看>>
iOS之隐藏状态栏
查看>>
Script:ASM修复脚本,寻找LISTHEAD和Kfed源数据
查看>>
mysql ERROR 1045 (28000): Access denied for user解决方法
查看>>
locale::facet::_S_create_c_locale name not valid
查看>>
shell 中的常用技巧
查看>>
25个增强iOS应用程序性能的提示和技巧--中级篇
查看>>