首页 技术 正文
技术 2022年11月8日
0 收藏 420 点赞 2,140 浏览 1502 个字

python 图像处理模块
1. 安装 pytesseract模块是会自动安装Pillow模块。
pillow 为标准图像处理库

手册地址 http://pillow-cn.readthedocs.io/zh_CN/latest/index.html
pytesseract 模块用于文字识别
pip3 install pytesseract
2. 安装 tesseract-ocr 这个用于文字识别
pytesseract 需要调用它
https://github.com/tesseract-ocr/tesseract/wiki
参考:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014320027235877860c87af5544f25a8deeb55141d60c5000
https://blog.csdn.net/dcba2014/article/details/78969658
https://blog.csdn.net/iodjSVf8U1J7KYc/article/details/79308086
3. 常见错误:
1. 注意使用python版本和安装模块的版本
2. ImageOps 需要使用 from PIL import ImageOps
不能直接使用PIL.ImageOps
3. 先引入
from lxml import html
from pyquery import PyQuery as pq
在引入
# 图片识别
from PIL import ImageOps
from PIL import Image
import pytesseract
发现报错误OSError: codec configuration error when reading image file
问题感觉比较奇葩
解决: 将图片库的引入在 pqquery 之前

例子1

转自:https://www.cnblogs.com/MrRead/p/7656800.html  有简单修改 让代码能在python3上运行

1、验证码的识别是有针对性的,不同的系统、应用的验证码区别有大有小,只要处理好图片,利用好pytesseract,一般的验证码都可以识别

2、我在识别验证码的路上走了很多弯路,重点应该放在怎么把图片处理成这个样子,方便pytesseract的识别,以提高成功率

python图片识别

3、原图为:

python图片识别

# 图片识别
from PIL import ImageOps
from PIL import Image
import pytesseract

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(‘8fnp.png’)
#图片的处理过程
im = im.convert(‘L’)
binaryImage = im.point(initTable(), ‘1’)
im1 = binaryImage.convert(‘L’)
im2 = ImageOps.invert(im1)
im3 = im2.convert(‘1’)
im4 = im3.convert(‘L’)
#将图片中字符裁剪保留
box = (30,10,90,28)
region = im4.crop(box)
#将图片字符放大
out = region.resize((120,38))
asd = pytesseract.image_to_string(out)
print(asd)
print (out.show())

python图片识别

上面代码可以识别出图片验证码

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,490
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290