19.验证码识别

2018-06-14  本文已影响0人  MononokeHime

Tesseract

tesseract是一个ORC(optical charactor recognition)库,目前由谷歌赞助。tesseract是目前公认最优秀,最准确的开源OCR库。tesseract具有很高的识别度,也具有很高的灵活度,他可以通过训练识别任何字体。

安装

tesseract识别图像:

tesseract a.png abc

a.png是要识别的图片,abc为识别后输出的文本。运行完成后,则多出abc.txt,记录着识别出的文字。

python中使用tesseract

在python中操作tesseract,需要安装一个库,叫做pytesseract。通过pip安装即可:

pip install tesseract

并且需要读取图片,需要借助第三方库叫做PIL。通过pip list看下是否安装。如果没有安装,通过:

pip install PIL

使用pytesseract将图片上的文字转换成文本文字:

import pytesseract
from PIL import Image

pytesseract.pytesseract.tesseract_cmd = r"D:\tesseract-Win64\tesseract.exe"

image = Image.open(r'D:\tesseract-Win64\1.png')

text = pytesseract.image_to_string(image)
# 选择其他语言
# text = pytesseract.image_to_string(image,lang='xxx')

print(text)
上一篇 下一篇

猜你喜欢

热点阅读