[深度学习] 百度开源api的ocr-demo
·
# 在终端pip install baidu-aip
from aip import ocr
import json
# 注意 aipocr改成了ocr.AipOcr
# https://login.bce.baidu.com/
# 在百度智能云,申请ocr的api,得到APP_ID,API_KEY,SECRET_KEY。
APP_ID = '0000'
API_KEY = '00000000'
SECRET_KEY = '0000000000 '
client = ocr.AipOcr(APP_ID, API_KEY, SECRET_KEY)
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
def image2text(fileName):
image = get_file_content(fileName)
dic_result = client.basicGeneral(image)
res = dic_result['words_result']
result = ''
for m in res:
result = result + str(m['words'])
return result
getresult = image2text('./2.png')
print(getresult)
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)