Linux Python Ocr图片识别

1.安装Tesseract

sudo yum install tesseract
sudo yum install tesseract-langpack-deu

2.安装Python pytesseract

sudo pip install pytesseract

3.安装其他依赖库(如果需要)

sudo yum install libjpeg-turbo-devel
sudo yum install libtiff-devel
sudo yum install libpng-devel

python使用代码

import pytesseract
from PIL import Image

# 设置Tesseract的路径(如果在系统PATH中未找到)
# pytesseract.pytesseract.tesseract_cmd = '/path/to/tesseract'

# 打开图片
image = Image.open('example.jpg')

# OCR识别
text = pytesseract.image_to_string(image, lang='chi_sim')

print(text)

注意点:

1.lang 指定识别的语言类型,否则乱码
2.指定语言后,运行找不到 chi_sim.traineddata 训练数据文件
下载对应数据文件放到 /usr/share/tesseract/tessdata 路径下
链接: https://pan.baidu.com/s/1_0ptWOJ9Sgh1r-QcOBY7Tw 
提取码: b6mw

评论

暂无评论