图片验证码的识别

import tesserocr
from PIL import Image
# 1.识别验证码
image = Image.open('code.jpg')
# result = tesserocr.image_to_text(image)
# print(result)

# 2.直接将图片文件转换为字符串
# print(tesserocr.file_to_text('code.jpg'))

# 3.验证码处理
# 灰度处理
# image = image.convert('L')
# image.show()

# 二值化处理
# image = image.convert('1')
# image.show()

image = image.convert('L')
threshold = 130
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)

你可能感兴趣的:(爬虫)