首页 > 解决方案 > Python pytesseract 解决验证码

问题描述

我正在尝试使用 pytesseract 模块在 python 中解决验证码。这是我的代码:

def captcha():
    image = cv2.imread('captcha.jpeg')

    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]

    #gray = cv2.medianBlur(gray, 3)

    filename = "{}.png".format("temp")
    cv2.imwrite(filename, gray)
    text = pytesseract.image_to_string(Image.open('temp.png'),
                                       config='--psm 8 -c tessedit_char_whitelist=0123456789abcdefghijkmnlopkrstuvwxyz')
    print('Captcha solved:' + text)

if __name__ == '__main__':
    captcha()

验证码采用以下格式:

验证码

计算的结果是:Captcha solved:“Fates当结果应该是182aa

标签: python-3.xcaptcha

解决方案


推荐阅读