安装tesseract库
安装tesseract库和它的python封装:
sudo apt install tesseract-ocr --fix-missing
sudo apt install libtesseract-dev
sudo pip install pytesseract
可以到tesseract的Github中下载训练好的中文数据模型
也可以通过百度网盘下载。
地址:https://pan.baidu.com/s/1uuSTBNo3byJib4f8eRSIFw
提取码:8v8u
将下载好的chi_sim.traineddata复制到/usr/share/tesseract-ocr/4.00/tessdata/目录下
sudo cp chi_sim.traineddata /usr/share/tesseract-ocr/4.00/tessdata
识别图像中的汉字
将用于测试的图片test.png保存在桌面。
新建一个test.py文件,输入
from PIL import Image
from pytesseract import *
img0 = Image.open('/home/pi/Desktop/test.png')
mychars = image_to_string(img0,'chi_sim').strip()
print(mychars)