当前位置: 首页 > 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)

相关文章:

  • 第十一次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
  • 地下5300米开辟“人造气路”,我国页岩气井垂深纪录再刷新
  • 新华时评:中美经贸会谈为全球经济纾压增信
  • 兵韬志略|美2026国防预算未达1万亿,但仍寻求“暗度陈仓”
  • 105岁八路军老战士、抗美援朝老战士谭克煜逝世
  • 正荣地产:董事会主席、行政总裁辞任,拟投入更多精力推动境内债重组等工作
  • 2024年上市公司合计实现营业收入71.98万亿元