python验证码图片处理(二值化)
作者:请叫我算术嘉 时间:2023-09-14 15:29:02
写在最前面:
这个我打算分几次写,由于我们通过selenium拿到的图片会很模糊,所以使用Tesseract识别之前要对图片先进行处理。
第一步就是二值化,设定阈值,低于阈值全部为白色(置0),其余黑色(置1)。
import pytesseract
from PIL import Image,ImageEnhance
def binaryzation(threshold=145): #降噪,图片二值化
table = []
for i in range(256):
if i < threshold:
table.append(0)
else:
table.append(1)
return table
image = Image.open('newcode.jpg') #打开图片
image = image.convert('L') #转化为灰度图
image.show()
image = image.point(binaryzation(), '1') #二值化
image.show()
这是原始图片 :
转化为灰度图:
二值化:
今天先到这儿,我要继续研究啦~
来源:https://blog.csdn.net/ssjdoudou/article/details/83832502
标签:python,验证码,二值化
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python提取视频帧图片实例代码
2023-02-11 18:15:21
![](https://img.aspxhome.com/file/2023/5/115195_0s.jpg)
OpenCV使用KNN完成OCR手写体识别
2022-02-17 12:16:21
![](https://img.aspxhome.com/file/2023/9/115079_0s.png)
查询表中某字段有重复记录个数的方法
2024-01-18 04:34:17
一文详解前端进阶之IntersectionObserver
2024-05-03 15:07:48
![](https://img.aspxhome.com/file/2023/0/130520_0s.png)
基于Jquery实现表单验证
2023-07-02 05:31:08
CentOS7 64位下MySQL5.7安装与配置教程
2024-01-17 16:32:12
![](https://img.aspxhome.com/file/2023/1/107911_0s.jpg)
Go语言字典(map)用法实例分析【创建,填充,遍历,查找,修改,删除】
2024-05-05 09:30:22
Python中根据时间自动创建文件夹的代码实现
2023-07-06 02:42:01
![](https://img.aspxhome.com/file/2023/1/95891_0s.png)
Python运行报错UnicodeDecodeError的解决方法
2022-03-21 17:21:40
IE事件对象(The Internet Explorer Event Object)
2024-02-26 01:55:18
python学生信息管理系统实现代码
2023-10-31 06:18:10
![](https://img.aspxhome.com/file/2023/1/90461_0s.jpg)
django rest framework使用django-filter用法
2023-03-06 01:56:06
![](https://img.aspxhome.com/file/2023/7/76007_0s.jpg)
php结合js实现点击超链接执行删除确认操作
2023-11-15 03:30:51
html注释所引起的一系列问题
2008-11-04 13:23:00
![](https://img.aspxhome.com/file/UploadPic/200811/4/1011310-54s.gif)
使用Pyinstaller转换.py文件为.exe可执行程序过程详解
2022-11-30 22:43:40
![](https://img.aspxhome.com/file/2023/8/79728_0s.png)
asp网上考试设计思路是怎样的?
2010-07-14 21:09:00
Python torch.onnx.export用法详细介绍
2022-04-28 22:07:33
![](https://img.aspxhome.com/file/2023/2/127882_0s.jpg)
python中三种输出格式总结(%,format,f-string)
2022-06-11 16:34:40
![](https://img.aspxhome.com/file/2023/6/75356_0s.png)
python3让print输出不换行的方法
2021-02-16 20:48:33
![](https://img.aspxhome.com/file/2023/8/121848_0s.png)
ie7.0浏览器 兼容问题苦煞网站设计者
2007-08-08 17:11:00