python验证码简单识别
使用pytesseract时得先安装tesseract,tesseract-ocr和pytesseract
from PIL import Imagefrom PIL import ImageEnhance
import pytesseract
import re
# 如果报错加上下面两行代码,更改tesseract路径
pytesseract.pytesseract.tesseract_cmd = 'D:\\Program Files\\Tesseract-OCR\\tesseract.exe'
tessdata_dir_config = '--tessdata-dir "D:\\Program Files\\Tesseract-OCR\\tessdata"'
im=Image.open("./img/10.jpg")
im=im.convert('L')
im.show()
im=ImageEnhance.Contrast(im)
im=im.enhance(1)
#im = im.resize((300, 90))
ltext = pytesseract.image_to_string(im)
#去掉非法字符,只保留字母数字
ltext = re.sub("\W", "", ltext)
im.show()
print(ltext)
#print(pytesseract.image_to_string(im))
#print(pytesseract.image_to_boxes(im))
#print(im.format, im.size, im.mode)
以上是 python验证码简单识别 的全部内容, 来源链接: utcz.com/z/388069.html