python - tesseract-ocr

1. 安装tesseract-ocr

下载链接:https://digi.bib.uni-mannheim.de/tesseract/
安装后添加环境变量
image
测试安装情况
image

2. 安装pytesseract

pip3 install pytesseract -i https://pypi.tuna.tsinghua.edu.cn/simple

3.添加中文包

下载链接:https://github.com/tesseract-ocr/tessdata_best
chi_sim.traineddata 为简体中文训练集
下载后放在 **\Tesseract-OCR\tessdata 目录

4. 脚本如下

from PIL import Image
import pytesseract
import cv2 as cv
img = Image.open('test.png')
pytesseract.pytesseract.tesseract_cmd = r'C:/Program Files/Tesseract-OCR/tesseract.exe'
res = pytesseract.image_to_string(img, lang='chi_sim')
print(res)

识别效果
image
image

posted @ 2023-03-20 21:37  wstong  阅读(49)  评论(0编辑  收藏  举报