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

原图:

第一种方法:

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

猜你喜欢

转载自www.cnblogs.com/euraxluo/p/9145962.html
今日推荐