python基于百度API的ORC文字识别
生活随笔
收集整理的這篇文章主要介紹了
python基于百度API的ORC文字识别
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
python基于百度API的ORC文字識別
- python基于百度API的ORC文字識別
python基于百度API的ORC文字識別
# encoding:utf-8import requests import base64# 文字識別模塊 高精度:https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic 普通:general_basic request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic" # 二進制方式打開圖片 f = open('C:\\Users\\bill_love_sea\\Desktop\\python\\20200617140056.jpg', 'rb') img = base64.b64encode(f.read()) # 獲取API相關的參數:access_token,headers,data 等 params = {"image": img} access_token = '24.253c31adc2d26d728940cf62c65013c0.2592000.1597372330.282335-21365498' request_url = request_url + '?access_token=' + access_token headers = {'content_type': 'application/x-www-form-urlencoded'} # 以POST方式進行請求 response = requests.post(request_url, data=params, headers=headers) # 輸出響應結果 if response:a = dict(response.json())for words in a['words_result']:print(words['words'])調取API的基本過程百度云的相關文檔都有,可以自行參考,其中‘access_token’參數的獲取如下:
# encoding:utf-8 import requests # client_id 為官網獲取的AK, client_secret 為官網獲取的SK AK = 'ysLHhFMBBGOq6wTZeoS6W6aX' SK = '9wioD22eKhFoyfv8rcdO01lzBunUq4S6' host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id='+AK+'&client_secret='+SK+'' response = requests.get(host) if response:print(response.json()['access_token'])總結
以上是生活随笔為你收集整理的python基于百度API的ORC文字识别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 投入产出表直接消耗系数和完全消耗系数St
- 下一篇: 微信小程序背景图片如何设置--如何用ba