当前位置: 首页 > article >正文

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)


http://www.kler.cn/a/589396.html

相关文章:

  • 【前端面试题】宏任务与微任务的区别
  • C语言之 循环语句:程序运行的核心动力(上)
  • vuex持久化存储,手动保存到localStorage
  • 奥林巴斯道Olympus DAO、奥拉丁模式、诺瓦银行、RWA模型合约解析开发
  • 大数据学习(70)-大数据调度工具对比
  • Navigation页面导航的使用
  • 基于javaweb的SpringBoot校园运动会管理系统设计与实现(源码+文档+部署讲解)
  • 6k ± 1 规则
  • 自然语言处理编程文档
  • 数组题型-二分查找-JS
  • 实战:自适应均衡的设计与实现
  • 【Docker】容器中安装cron命令
  • 使用 Docker 部署 MySQL 8
  • TensorFlow 基本原理与使用场景
  • 移除元素(快慢指针)
  • Linux第六讲----git与gdb
  • 文本检测-文本内容审核-文本过滤接口如何用PHP调用?
  • 市长海报/ Mayor‘s posters
  • L2-3 花非花,雾非雾
  • maven使用install将jar包编译到本地仓库管理