当前位置:   article > 正文

python 百度识图_python如何调用百度识图api

python封装百度的搜图api

python如何调用百度识图api,接口,详细内容,相关文章,先去,更多关于

python如何调用百度识图api

易采站长站,站长之家为您整理了python如何调用百度识图api的相关内容。

一.先去百度识别官网注册开通服务且获得ak和sk

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

二.代码模板

import cv2

import base64

import requests

import numpy as np

import traceback

from retrying import retry

token_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_token

def 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 words

def 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如何调用百度识图api的详细介绍。欢迎大家对python如何调用百度识图api内容提出宝贵意见

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/771512
推荐阅读
相关标签
  

闽ICP备14008679号