Python3.4 验证码识别

2019PHP高薪工程师学习路线图....>>>

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()