import os
from aip import AipOcr
print("正在努力识别中,请耐心等待".center(60))
APP_ID = '20225407'
API_KEY = 'zWGe7eiBpxqK3DXCRGW7hg1h'
SECRET_KEY = 'Ch3VXkshTVOLICUYIY2vkvOAOnacPQRa'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
BASE_DIR = os.getcwd()
id_list = os.listdir(os.path.join(BASE_DIR, "要识别的图片"))
success_path = os.path.join(BASE_DIR, "successful.txt")
count = 0
for Id in id_list:
img = open(os.path.join(BASE_DIR, "要识别的图片", Id), 'rb').read()
msg = client.basicGeneral(img)
str1 = ""
for i in msg["words_result"]:
print("{}".format(i["words"]).center(60))
str1 += "{}\n".format(i["words"])
with open(success_path, 'a') as f:
f.write("{}\n\n".format(str1))
print("\n")
print("写入中,请稍等。。。".center(60))
count += 1
print("\n\n")
print("执行结束,共完成了{}图片的识别,资料已写入到successful.txt".format(count).center(60))
ss = input("")
以上是照别人的代码敲的,如果有侵权,请联系,我立刻就删。
文章的目的是自己学习代码结构和练手用的,不用于任何商业目的。