国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

python如何調用百度識圖api

瀏覽:58日期:2022-07-09 13:55:16

一.先去百度識別官網注冊開通服務且獲得ak和sk

鏈接:https://cloud.baidu.com/doc/Reference/s/9jwvz2egb

二.代碼模板

import cv2import base64import requestsimport numpy as npimport tracebackfrom retrying import retrytoken_list=[ { 'ak':'xxxxxx', 'sk':'xxxxxxxxxx' },]def get_token(ak,sk): url = 'https://aip.baidubce.com/oauth/2.0/token' params = { 'grant_type': 'client_credentials', 'client_id': ak, # AK 'client_secret': sk # SK } eaders={ 'Content-Type':'application/json; charset=UTF-8', } response = requests.get(url,params=params,headers=headers,timeout=8) res = response.json() access_token = res['access_token'] return access_tokendef baidu_api(image,token): ''' 百度通用文字識別 :return: ''' # 通用文本識別接口 url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic' # 網絡圖片識別接口 # url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/webimage' params = { 'access_token': token, } data = { 'image': base64.b64encode(image) #圖標的bs64編碼 } response = requests.post(url, params=params, data=data) data_res = response.json() print(data_res) words = [i['words'] for i in data_res['words_result']] return wordsdef baidu_image_recognition(img_content): img2=img_content for i in range(len(token_list)): token = get_token(token_list[i]['ak'], token_list[i]['sk']) words = baidu_api(img2,token) return words

以上就是python如何調用百度識圖api的詳細內容,更多關于python調用api的資料請關注好吧啦網其它相關文章!

標簽: 百度 Python
相關文章:
主站蜘蛛池模板: 道真| 宣汉县| 武鸣县| 重庆市| 基隆市| 中江县| 驻马店市| 万山特区| 翁牛特旗| 临洮县| 兴海县| 民勤县| 北海市| 高台县| 静乐县| 古蔺县| 津南区| 武山县| 桃园市| 全椒县| 泸定县| 交口县| 西乌| 恩平市| 泽库县| 乌鲁木齐县| 黄大仙区| 木里| 麟游县| 宝清县| 如皋市| 毕节市| 常山县| 荔浦县| 于田县| 荣成市| 会昌县| 曲沃县| 石景山区| 崇礼县| 河源市|