【百度人脸识别】》人脸检测接口调用

相关文档

https://cloud.baidu.com/doc/FACE/s/yk37c1u4t

接口详细相关参数请参考开发文档

代码:

import base64
import json

import requests
from flask import Flask, jsonify
from constants import API_Key, Secret_Key

app = Flask(__name__)


@app.route('/face_detection')
def detection():
    Access_Token = None
    # 获取调用接口所需的AccessToken
    host = f'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={API_Key}&client_secret={Secret_Key}'
    response = requests.get(host)
    if response:
        # print(response.json())
        Access_Token = response.json().get('access_token')
        print(Access_Token)
    # 进行人脸检测调用接口
    with open("903.jpg", "rb") as f:
        # b64encode:编码,b64decode: 解码
        base64_903 = base64.b64encode(f.read())
    headers = {'content-type': 'application/json'}
    payload = json.dumps(
        {
            'image': str(base64_903, 'utf-8'),
            'image_type': 'BASE64',
         }
    )
    URL = 'https://aip.baidubce.com/rest/2.0/face/v3/detect' + "?access_token=" + Access_Token
    resp = requests.post(URL, data=payload, headers=headers)
    if resp:
        print(resp.json())
        return jsonify(resp.json())
    return jsonify('出错了!!!')
if __name__ == '__main__':
    app.run()

返回结果:

 

人脸对比接口调用代码相关链接:

https://blog.csdn.net/h18208975507/article/details/109000613

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值