总结:  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 之前

 

posted on 2018-07-14 19:38  swing07  阅读(623)  评论(0编辑  收藏  举报