首页 > 技术文章 > OCR图片文字识别

zhangbojiangfeng 2022-05-06 16:07 原文

 1 #从相应的aip导入AipOcr模块
 2 from aip import AipOcr
 3 from pandas.core.frame import DataFrame
 4 #输入凭证
 5 APP_ID="19307867"
 6 API_Key="HM1UDlzRPrr7TE6xw9YHDSnZ"
 7 Secret_Key="6jUGVGRLMrbByWz0vPs5w5NOS8m6GMOl"
 8 aipOcr=AipOcr(APP_ID,API_Key,Secret_Key)
 9 
10 """
11 #输入资源
12 filePath=r"路基名"
13 for i in range(1,图片编号):
14     filePath1=filePath+"\\"+"图片名(带编号的)".#最好是jpg,名称统一
15     image=open(filePath1,"rb").read()
16 """
17 file='/Users/admin/Desktop/test02.jpeg'
18 image=open(file,"rb").read()
19 #接通ocr接口
20 result=aipOcr.basicGeneral(image)
21 #输出
22 #mywords=result["words_result"]
23 # for i in range(len(mywords)):
24 #    print(mywords[i]["words"])
25 # del_index=[len(mywords)-2,len(mywords)-1,0,1,2]
26 # new_data=[mywords[i] for i in range (0,len(mywords))  if i not in del_index]
27 # final=[]
28 # for i in range(0,len(new_data)):
29 #     if i % 2 ==0 and i < len(new_data)-1:
30 #         day=new_data[i]["words"]
31 #         data=new_data[i+1]["words"]
32 #         final.append([day,data])
33 # df=DataFrame(final,columns=['day','data'])
34 # df.to_csv('202009_data.csv')

 

推荐阅读