我正在尝试使用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