百度AI中图像识别的调用

(1)首先需要通过API Key和Secret Key获取access_token
输入:

import requests
import base64

'''
菜品识别
'''

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

params = {"image":img,"top_num":5}
access_token = '24.8b7fed2d558472cb28d9f2e6b7592ee5.2592000.1579144770.282335-18043433'
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())

输出:

菜品识别的输出代码

(2 )接着对菜品进行识别
输入:

import requests
import base64

'''
菜品识别
'''

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

params = {"image":img,"top_num":5}
access_token = '24.8b7fed2d558472cb28d9f2e6b7592ee5.2592000.1579144770.282335-18043433'
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())

输出:

菜品识别的输出代码

你可能感兴趣的:(百度AI中图像识别的调用)