
安装pytesseract包:pip install pytesseract
import cv2
import sys
import pytesseract
if __name__ == '__main__':
#imgpath = './imgs9/0000000001.jpg'
imgpath ='C:/Users/Administrator/Desktop/test1.png'
img = cv2.imread(imgpath, cv2.IMREAD_ANYCOLOR)
# 参数说明
# -l chi_sim -l l是language的缩写 -l 指定识别的语言类型 后面跟到chi_sim为中文简体训练数据/tessdata/chi_sim.traineddata 根据需求写
#--oem 使用LSTM作为OCR引擎 枚举值有0,1,2,3
# 0 Legacy engine only
# 1 Neural nets LSTM engine only
# 2 Legacy +LSTM engines (0 + 1)
# 3 Default, based on what is available
#--psm 设置 page Segmentation模式为自动
config = ('-l chi_sim --oem 1 --psm 3')
text = pytesseract.image_to_string(img, config = config)
print(text)运行结果:

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。