python 识别图形验证码

2022-05-13 10:09:20 浏览数 (1)

import tesserocr from PIL import Image

ima = Image.open('1.png') image=ima.resize((480,200),Image.ANTIALIAS) image = image.convert('L')

这个是二值化阈值

threshold = 160 table = [] for i in range(256): if i < threshold: table.append(0) else: table.append(1)

通过表格转换成二进制图片,1的作用是白色,不然就全部黑色了

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

print(tesserocr.image_to_text(image)[:5]) # print ocr text from image

0 人点赞