
pip install baidu-aip |
from aip import AipOcr #导入AipOcr模块,用于做文字识别 |
import glob |
APP_ID = '你申请的' |
API_KEY = '你申请的' |
SECRET_KEY = '你申请的' |
client = AipOcr(APP_ID, API_KEY, SECRET_KEY) |
path = "红楼梦\\" |
files = glob.glob(path+"*.png") |
txt_file = open('红楼梦.txt', 'a') |
for file in files: |
pic = open(file,'rb')#以二进制(rb)打开 |
img = pic.read() #读取 |
message = client.basicGeneral(img) #调用百度AI识别图片中的文字 |
for words in message['words_result']: |
word = words['words'] #提取文字 |
print(word) |
txt_file.write(word) #将文字写入文本文件 |
txt_file.close() #关闭文本文件 |



