import pytesseract
from PIL import Image
text = pytesseract.image_to_string(Image.open(r"E:\report\chen\4.png"), lang='chi_sim')
print(text)
运行结果
D:\Python3.8.6\python.exe D:/PythonWorkSpace/Auto_test_wuhan/common/utils/char_recognize.py
空 调
Process finished with exit code 0
图片文字识别的代码很简单,难就难在文件的配置、环境变量、语言包的下载。下面是我遇到的问题及解决方法
语言包Tesseract OCR 下载安装 (中英文语言包) 下载路径如下
1.GitHub - tesseract-ocr/tessdata: Trained models with support for legacy and LSTM OCR engine
2.找到简中的语言包下载完后安装Tesseract-OCR
3.安装完成后需要配置环境变量