Python3.4 驗證碼識別

pe6y 9年前發布 | 6K 次閱讀 Python

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

 本文由用戶 pe6y 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!