首页 > 其他 > 详细

两种去噪方法对比,验证码识别

时间:2018-06-06 17:17:23      阅读:151      评论:0      收藏:0      [点我收藏+]

原图:技术分享图片

 

第一种方法:

image_file = Image.open("222365983497055298.png")
image_file = image_file.convert(1)
image_file.save("quzao.png")

结果:技术分享图片

 

第二种方法:

def ChangeRGB():
    im = Image.open("222365983497055298.png")
    print("image info ",im.format,im.mode,im.size)
    (w,h) = im.size
    R = 0
    G = 0
    B = 0
    for i in range(w):
        for j in range(h):
            point = (i,j)
            rgb = im.getpixel(point)
            (r,g,b) = rgb
            R = R+r
            G = G+g
            B = B+b
    rate1 = R*1000/(R+G+B)
    rate2 = G*1000/(R+G+B)
    rate3 = B*1000/(R+G+B)
    print("rate",rate1,rate2,rate3)

    for i in range(w):
        for j in range(h):
            point = (i,j)
            rgb = im.getpixel(point)
            (r,g,b) = rgb
            n = r * rate1 / 1000 + g * rate2 / 1000 + b * rate3 / 1000
            if n >= 90:
                im.putpixel(point, (255, 255, 255))
            else:
                im.putpixel(point, (0, 0, 0))
    im.save("quzao2.png")

if __name__=="__main__":
    ChangeRGB()

处理效果随着:

if n >= 90:
    im.putpixel(point, (255, 255, 255))
else:
    im.putpixel(point, (0, 0, 0))

中的n的值变化,结果:技术分享图片

 

还有干扰线的去除:这里有个C#的代码,我学习的这个 https://www.cnblogs.com/fuchongjundream/p/5403193.html

 

两种去噪方法对比,验证码识别

原文:https://www.cnblogs.com/euraxluo/p/9145962.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!