【python】初学者

【Python】识别图片验证码

2019-04-11  本文已影响71人  米兰的小铁匠

预言

注意

安装

tesseract下载地址:https://digi.bib.uni-mannheim.de/tesseract/
下载未带dev的稳定版本;

实例

import tesserocr
from PIL import Image

image = Image.open('01.jpg')# 放入图片的绝对路径
result = tesserocr.image_to_text(image)
print(result)
示例输出:nVNA
image = image.convert("L")
image.show
image = image.convert("1")
image.show
image = image.convert('L')
threshold = 80
table = []
for i in range(256):
    if i < threshold:
        table.append(0)
    else:
        table.append(1)
image = image.point(table, '1')
image.show()
# 完整代码
import tesserocr
from PIL import Image

image = Image.open('01.jpg')# 放入图片的绝对路径
image = image.convert('L')
threshold = 80
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)

结语

上一篇 下一篇

猜你喜欢

热点阅读