驗證碼識別

# -*- coding: utf-8 -*-

import urllib.request, urllib.parse
from PIL import Image
from pytesseract import *

# '''
# 獲取驗證碼
# '''
# auth_img_url = r'http://www.myexception.cn/img/2014/10/22/13370857.jpg'
# urllib.request.urlretrieve(auth_img_url, 'auth.jpg')
#
# '''
# 對圖像進行灰度化,二值化處理
# '''
img = Image.open(r"C:\Users\Administrator\Desktop\視頻\1.gif")
img_gray = img.convert('L')

threshold = 140
table = []
for i in range(256):
    if i < threshold:
        table.append(0)
    else:
        table.append(1)

out = img_gray.point(table, '1')
# out.save('auth_b.jpg')

'''
識別驗證碼中的文字
'''
auth = pytesseract.image_to_string(out)

print(auth)
相關文章
相關標籤/搜索