简单图片验证码

一  简单版(不加噪线)

import tesserocr
from PIL import Image

image = Image.open('code2.jpg')
result = tesserocr.image_to_text(image)
print(result)

#下面这种方式,识别正确率不高
import tesserocr
print(tesserocr.file_to_text('code.jpg')

二  复杂版本(验证图片有噪线)

import tesserocr
from PIL import Image

image = Image.open('code2.jpg')

image = image.convert('L')  #转灰度
threshold = 127  #127是默认的二值化阈值,也可以设定其他的数值
table = []
for i in range(256):
    if i < threshold:
        table.append(0)
    else:
        table.append(1)

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

result = tesserocr.image_to_text(image)
print(result)#可以准确识别出数字或是字母
原文地址:https://www.cnblogs.com/lxx7/p/10678279.html