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

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.dtcms.com/a/74007.html

相关文章:

  • 第十一次CCF-CSP认证(含C++源码)
  • TensorFlow 基本原理与使用场景
  • 【SpringBatch】01简单入门
  • 简要分析NLMSG_DONE参数
  • Ubuntu下升级node.js从12.22到22.14
  • 商业智能BI分析中,汽车4S销售行业的返厂频次有什么分析价值?
  • 查看IP地址/Ping 命令
  • TX-LCN 框架
  • Couchbase Analytics 页面右侧的“Analytics Scopes, Links, Collections”等的解释
  • 在 ARM 嵌入式 Linux 下使用 C/C++ 实现 MQTT
  • HCIA-Access V2.5_14_3_1系统基本操作_管理操作用户
  • RxSwift 学习笔记第四篇之RxSwift在项目中的简单应用
  • Unix时间戳BKP备份寄存器RTC实时时钟
  • C# 不同框架如何调用framework 和 net core
  • 蓝桥杯 刷题统计
  • Vue:添加响应式数据
  • Mysql中创建表时的约束条件
  • 使用Dependency Walker和Beyond Compare快速排查dll动态库损坏或被篡改的问题
  • JavaScript如何做类型转换
  • Python文字识别OCR
  • 麒麟服务器操作系统QT系列软件工具手册
  • 双指针算法-day11(双序列双指针)
  • 用hexo初始化博客执行hexo init时碰到的问题
  • 【即插即用涨点模块】EGA边缘引导注意力:有效保留高频边缘信息,提升分割精度,助力高效涨点【附源码+注释】
  • 告别硬编码:优雅管理状态常量与响应码
  • Ansible Facts变量
  • 相对论之光速
  • IP地址分配
  • Python 中用T = TypeVar(“T“)这个语法定义一个“类型变量”,属于类型提示系统的一部分
  • Java学习打卡-Day18-ArrayList、Vector、LinkedList