美文网首页
文物识别API调用测试

文物识别API调用测试

作者: 2_Soon | 来源:发表于2020-07-19 00:43 被阅读0次

物体识别API测试

获取token

# encoding:utf-8
import requests 

# client_id 为官网获取的AK, client_secret 为官网获取的SK
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())

文物识别

# encoding:utf-8

import requests
import base64

'''
通用物体和场景识别
'''

request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general"
# 二进制方式打开图片文件
f = open('./簪花仕女图.png', 'rb')
img = base64.b64encode(f.read())

params = {"image":img}
access_token = '[调用鉴权接口获取的token]'
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    print (response.json())

输出内容

{'log_id': 8705286469577267761, 'result_num': 5, 'result': [{'score': 0.823557, 'root': '商品-工艺品', 'keyword': '绘画'}, {'score': 0.578453, 'root': '商品-绘画', 'keyword': '图画'}, {'score': 0.386313, 'root': '非自然图像-彩色动漫', 'keyword': '卡通动漫人物'}, {'score': 0.210961, 'root': '非自然图像-文字图', 'keyword': '报纸杂志'}, {'score': 0.027196, 'root': '人物-人物特写', 'keyword': '美女'}]}

相关文章

网友评论

      本文标题:文物识别API调用测试

      本文链接:https://www.haomeiwen.com/subject/chgqkktx.html