Python3.4 验证码识别详解编程语言

from PIL import Image, ImageEnhance   
Mods = []   
for i in range(10):   
    Mods.append((str(i), Image.open('D:/Python源码/图片/%d-.png' % i)))   
def regonize():   
    for n in range(50):   
        image = Image.open('D:/Python源码/图片/%d.png' % n)   
        image2 = image.convert('1')   
        result = []   
        for i in range(4):    #将验证码分割4份   
            w1 = 23          #根据验证码大小确定,为宽度   
            box = (w1*i, 0, w1+w1*i, 37)   
            image_crop = image2.crop(box)   
            points = []   
            for Mod in Mods:   
                different = 0   
                for y in range(23):   
                    for x in range(37):   
                        if y  > 0 and x > 0:   
                            if (Mod[1].getpixel((y-1, x-1)) != image_crop.getpixel((y-1, x-1))):   
                                different += 1   
                points.append((different, Mod[0]))   
                points.sort()   
            result.append((points[0][1]))   
        print(result, n)   
regonize()  

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/8051.html

(0)
上一篇 2021年7月18日 19:17
下一篇 2021年7月18日 19:17

相关推荐

发表回复

登录后才能评论