# 在终端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)
[深度学习] 百度开源api的ocr-demo
最新推荐文章于 2021-06-04 21:49:22 发布