美文网首页
百度AI中图像识别的调用

百度AI中图像识别的调用

作者: 滢_ | 来源:发表于2019-12-26 00:32 被阅读0次

    (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中图像识别的调用

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