python调用百度人脸识别接口

1 百度智能云-登录或注册

 2 拿到 app_id='', api_key='', secret_key=''

pip install baidu-aip
pip install chardet

123.png

script.py

# script.py

import base64
from aip import AipFace

class BaiDuFace:
    def __init__(self, app_id='xxx', api_key='xxx', secret_key='xxx'):
        self.app_id = app_id
        self.api_key = api_key
        self.secret_key = secret_key
        self.client = AipFace(self.app_id, self.api_key, self.secret_key)

    def add_user(self):
        # 修复文件读取问题,使用base64.b64encode对图片进行编码
        with open('./xxx.png', 'rb') as fp:
            image = base64.b64encode(fp.read()).decode('UTF-8')  # 将图片编码为Base64字符串
        imageType = 'BASE64'
        groupId = "100"
        userId = 'dilireba'

        options = {}
        options['user_info'] = '这是迪丽热巴'
        options['quality_control'] = 'NORMAL'
        options['liveness_control'] = 'LOW'
        options['action_type'] = 'REPLACE'


        res=self.client.addUser(image, imageType, groupId, userId)
        return res

    def delete(self):
        userId = "dilireba"
        groupId = '100'
        faceToken = 'bba76dcb9535d68553377853ac5462c1'

        res = self.client.faceDelete(userId, groupId, faceToken)
        return res

    def search(self):
        """
        搜索人脸方法
        :param image_path: 输入图像路径
        :param group_id_list: 人脸库分组ID列表,用逗号分隔
        :return: 搜索结果
        """
        with open('./xxx.png', 'rb') as fp:
            image = base64.b64encode(fp.read()).decode('UTF-8')
        imageType = 'BASE64'

        groupIdList='100'

        res = self.client.search(image, imageType, groupIdList)
        return res


if __name__ == '__main__':
    ai=BaiDuFace()
    res=ai.delete()
    print(res)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值