天天看点

pytesseract自动识别图像文本使用方法

tesseract的安装方法在tesseract安装方法

from PIL import Image
import pytesseract

#指定tesseract驱动程序的安装路径,
pytesseract.pytesseract.tesseract_cmd = r"D:/tesseract-install/Tesseract-OCR/tesseract.exe"

#实例化一个图像对象
image = Image.open("./data/a.png")

#将图像转化为字符串
text = pytesseract.image_to_string(image)

print(text)
           

a.png为

pytesseract自动识别图像文本使用方法

输出结果为

5201314cy

Process finished with exit code 0