python实现简单验证码识别

  1. 安装python和pip不作介绍,保证打开cmd输入pip和python有反应。需设置环境变量。python3.6安装包
  2. 在cmd中执行以下命令(怎么启动cmd)
1
2
3
pip install PIL
pip install Pillow
pip install pytesseract
  1. 目标图片
    验证码

  2. 识别代码(python3)
    如果出现无法导入需要自己解决依赖问题

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    from PIL import Image
    from pytesseract import *


    im = Image.open('index.png')

    im = im.convert('L')
    def initTable(threshold=140):
    table = []
    for i in range(256):
    if i < threshold:
    table.append(0)
    else:
    table.append(1)

    return table

    binaryImage = im.point(initTable(), '1')
    #binaryImage.show()

    print(image_to_string(binaryImage, config='-psm 7'))
  3. 结果截图
    结果

其它

参考链接