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()
以上适用于一般验证码,http://write.blog.csdn.net/post
edit

转载注明此处

 
 

你可能感兴趣的:(图片处理,PIL,python,验证码,验证码识别)