python 豆瓣验证码识别总结

总结:  pytesseract 识别比较标准的图片  识别成功率   还是不错的。

验证码的图片识别 需要先处理好   再用pytesseract 识别

 

from PIL import Image  # 图片处理
import pytesseract  #  识别

im = Image.open('/home/yuexinpeng/profit.jpg')
out = im
aa = pytesseract.image_to_string(out)
print(aa)

 

# 滤波处理 去掉背景色
threshold = 37
width, height = im.size
for i in range(0, width):
for j in range(0, height):
p = im.getpixel((i, j))
r, g, b = p
if r > threshold or g > threshold or b > threshold:
# self.frame[i, j] = WHITE
im.putpixel((i,j),(255,255,255))
else:
# self.frame[i, j ] = BLACK
im.putpixel((i,j),(0,0,0))

 

# 保存和识别图片

# 中值滤波

im = im.filter(ImageFilter.MedianFilter())
im.save('profit-filter.jpg')
aa = pytesseract.image_to_string(im)
print(aa)

 

参考:

image图片处理函数

https://blog.csdn.net/l297969586/article/details/70240123

验证处理思路

http://ju.outofmemory.cn/entry/162281

 图像滤波处理

https://blog.csdn.net/guduruyu/article/details/71404941

 

python 图像处理模块
1. 安装 pytesseract模块是会自动安装Pillow模块。
pillow 为标准图像处理库
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
常见错误:
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 之前

 

转载于:https://www.cnblogs.com/swing07/p/9310772.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值