程序如下:
from aip import AipOcr
import codecs
import os
#读取图片函数
def ocr(path):
with open(path,'rb') as f:
return f.read()
def main():
filename = "00030.jpg"
print("已经收到,正在处理,请稍后....")
APP_ID = ' '
API_KEY = ' '
SECRET_KEY = ' '
client = AipOcr(APP_ID, API_KEY,SECRET_KEY)
#读取图片
image = ocr(filename)
#进程OCR识别
# dict1 = client.basicGeneral(image)
dict1 = client.basicAccurate(image)
# print(dict1)
with codecs.open(filename + ".txt","w","utf-8") as f:
for i in dict1["words_result"]:
f.write(str(i["words"] + "\r\n"))
print ("处理完成")
if __name__ == '__main__':
main()