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()
效果圖:

