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)

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐