美文网首页
Python识别简单验证码(二)demo

Python识别简单验证码(二)demo

作者: sunland_0416 | 来源:发表于2020-10-21 08:40 被阅读0次

环境:python 3.6.5
pillow 7.0.0
pytesseract-0.3.6
下面是一个简单的识别demo

import re
from PIL import Image
import pytesseract  #  https://tesseract-ocr.github.io/tessdoc/4.0-with-LSTM

if __name__ == '__main__':
    img_path=r"E:\python_project\img\7364.png"
    img=Image.open(img_path)

    image = img.convert('L')  # 转化为灰度图
    threshold = t  # 设定的二值化阈值
    table = []
        for i in range(256):
            if i < threshold:
                table.append(0)
            else:
                table.append(1)

    image = image.point(table, '1')

    pytesseract.pytesseract.tesseract_cmd = r"D:\Program Files\Tesseract-OCR\tesseract.exe"
    result = pytesseract.image_to_string(image)  # 图片转文字
    print(result)
    print(str(t))
7364.png

相关文章

网友评论

      本文标题:Python识别简单验证码(二)demo

      本文链接:https://www.haomeiwen.com/subject/ydksmktx.html