第一步:安装pytesseract包,但仅安装包不够,还需要安装tesseract应用程序
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pytesseract
第二步:去官网下载exe
https://github.com/UB-Mannheim/tesseract/wiki
第三步:可以运行一个简单的示例了
测试图片 test.png
import pytesseract
from PIL import Image
pytesseract.pytesseract.tesseract_cmd = 'D:/Tesseract-OCR/tesseract.exe' # 这里需要改成自己的安装地址
text = pytesseract.image_to_string(Image.open('test.png'), lang="eng")
print(text)
运行结果:
C:\Users\cgh\anaconda3\envs\tensorrt\python.exe F:/PyCharmProjects/test/ocr.py
178319754
666063712
10842192
1170860496
42603815
26550568
260200544
92280335
4935815
29262313
进程已结束,退出代码0