8.1 图形验证码的识别
win10 64, 先安装tesseract.exe,再安装tesserocr模块报错,而因事先安装了VC++ build tools, 只需再安装.whl
import tesserocr
from PIL import Image
image = Image.open('CheckCode.jpg')
# 灰度处理
image = image.convert('L')
# 二值化处理
threshold = 160 # 修改这个阈值,可以得到目标图像
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)