Python识别中的文字
1 利用百度OCR功能(需电脑联网等百度账号)
参照https://www.cnblogs.com/chunfang/p/13234289.html
pip install baidu-aip
2. 本地安装Tesseract
pip install pytesseract 文字识别
pip install pillow 图片读取import os
import pytesseract# 文字图片的路径path = 'text_img/'# 获取图片路径列表imgs = [path + i for i in os.listdir(path)]# 打开文件f = open('text.txt', 'w+', encoding='utf-8')# 将各个图片的路径写入text.txt文件当中for img in imgs: f.write(img + '\n')# 关闭文件f.close()# 文字识别string = pytesseract.image_to_string('text.txt', lang='chi_sim') # 指定中文后,英文仍可识别print(string)
浙公网安备 33010602011771号