1.登录百度云平台,创建应用
2.编写代码
from aip import AipOcr import codecs import os #读取图片函数 def ocr(path): with open(path,‘rb‘) as f: return f.read() def main(): filename = "c.jpg" print("已经收到,正在处理,请稍后....") app_id = ‘16193547‘ api_key = ‘B0R5gbezdGSzCY4oIlOpuLy8‘ secret_key = ‘CyevG1PTfpPvkw9vwItPdya09GrzZ462‘ client = AipOcr(app_id,api_key,secret_key) #读取图片 image = ocr(filename) #进程OCR识别 dict1 = client.general(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()
效果图:
原文:https://www.cnblogs.com/students/p/10826822.html