百度云AI

百度云AI概述

  • Face++
  • 腾讯优图
  • 科大讯飞

百度人脸识别基于深度学习的人脸识别方案,准确识别图片中的人脸信息,提供如下功能:

  • 人脸检测:精准定位图中人脸,获得眼、口、鼻等72个关键点位置,分析性别、年龄、表情等多种人脸属性
  • 人脸对比:对比两张人脸的相似度,并给出相似度评分,从而判断是否同一个人
  • 人脸搜索:针对一张人脸照片,在指定人脸集合中搜索,找出最相似的一张脸或多张人脸,并给出相似度分值
  • 活体检测:提供离线/在线方式的活体检测能力,判断操作用户是否为真人,有效抵御照片、视频、模具等作弊攻击
  • 视频流人脸采集:设备端离线实时监测视频流中的人脸,同时支持处理静态图片或者视频流,输出人脸图片并进行图片质量控制

百度云AI的开发步骤

  1. 注册账号创建应用
  2. 搭建工程导入依赖
  3. 人脸注册
  4. 人脸识别

百度云AI的注册与认证

(1)注册百度云帐号

https://login.bce.baidu.com/new-reg?tpl=bceplat&from=portal

在这里插入图片描述
激活人脸识别,并创建应用
在这里插入图片描述
应用创建完成之后,进入刚刚创建的应用获取开发所需的AppID,API Key,Secret Key。
在这里插入图片描述

百度云API的入门

搭建环境

创建工程并导入依赖:

<dependency>
  <groupId>com.baidu.aip</groupId>
   <artifactId>java-sdk</artifactId>
   <version>4.8.0</version>
</dependency>

人脸注册

用于从人脸库中新增用户,可以设定多个用户所在组,及组内用户的人脸图片
典型应用场景:构建您的人脸库,如会员人脸注册,已有用户补全人脸信息等。

public class FaceTest {
    //人脸注册
    @Test
    public void testFaceRegister() throws Exception {
     //创建java代码和百度云交互的clent对象
     AipFace client = new AipFace("你的AppID", "你的API Key", "你的Secret Key");
     //传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("quality_control", "NORMAL"); //设置质量控制参数,可选值为NORMAL(默认)NONE、LOW。HIGH模式会进行更严格的人脸质量检测,若检测不通过,则会返回不通过的错误码。
        options.put("liveness_control", "LOW");//设置活体检测参数,可选值为NONE(默认)LOW、NORMAL、HIGH。NONE模式不进行活体检测,直接返回结果。LOW模式会进行非常简单的活体检测,FAST模式会进行快速的活体检测,FAST模式会更关注速度,而可能增加误识率。HIGH模式会进行非常严格的活体检测,
        String imageType = "BASE64";
        String groupId = "yu";
        String userId = "0001";
//构造base64图片字符串
        String path = "C:\\Users\\ZZZYY\\3D Objects\\gx.jpg";
        byte[] bytes = Files.readAllBytes(Paths.get(path));
        String image = Base64Util.encode(bytes);
// 人脸注册
        /**
         * @param image 本地图片路径,支持jpg、png、gif、bmp,不支持base64。
         *              imageType 可选值为BASE64、URL,不填默认为BASE64。
         *              groupId 用户组ID,必填。
         *              userId 用户ID,必填。
         *              options 可选参数,json格式。
         */
        JSONObject res = client.addUser(image, imageType, groupId, userId, options);
        System.out.println(res.toString(2));
    }
}

人脸注册 请求参数详情
在这里插入图片描述
人脸注册 返回数据参数详情
在这里插入图片描述
运行控制台输出

{
  "result": {
    "face_token": "6dd622d4ac489e3***",
    "location": {
      "top": 186.57,
      "left": 215.43,
      "rotation": 1,
      "width": 285,
      "height": 302
    }
  },
  "log_id": 2227089050,
  "error_msg": "SUCCESS",
  "cached": 0,
  "error_code": 0,
  "timestamp": 1707968227
}

查看人脸库
在这里插入图片描述

人脸检测

人脸检测:检测图片中的人脸并标记出位置信息;

    //人脸检测
    @Test
    public void testFaceDetect() throws IOException {
        String path = "C:\\Users\\ZZZYY\\3D Objects\\logo.png";
        byte[] bytes = Files.readAllBytes(Paths.get(path));
        String image = Base64Util.encode(bytes);
        String imageType = "BASE64";
        HashMap<String, String> subOptions = new HashMap<String, String>();
        subOptions.put("max_face_num", "10");
        //人脸检测
        JSONObject res = client.detect(image, imageType, subOptions);
        System.out.println(res.toString(2));
    }
}

人脸检测 请求参数详情
在这里插入图片描述
人脸检测 返回数据参数详情
在这里插入图片描述
在这里插入图片描述
运行控制台输出

{
  "result": null,
  "log_id": 124186657,
  "error_msg": "pic not has face",
  "cached": 0,
  "error_code": 222202,
  "timestamp": 1707969724
}

换张有人脸图,在运行输出

{
  "result": {
    "face_num": 1,
    "face_list": [{
      "angle": {
        "roll": -12.3,
        "pitch": 1.94,
        "yaw": -0.55
      },
      "face_token": "6bca071e248a56e212*****",
      "location": {
        "top": 170.58,
        "left": 214.3,
        "rotation": -9,
        "width": 181,
        "height": 185
      },
      "face_probability": 1
    }]
  },
  "log_id": 363572715,
  "error_msg": "SUCCESS",
  "cached": 0,
  "error_code": 0,
  "timestamp": 1707969963
}

人脸搜索

在指定人脸集合中,找到最相似的人脸

    //人脸搜索
    @Test
    public void testFaceSearch() throws IOException {
        String path = "C:\Users\ZZZYY\3D Objects\cgx.jpeg";
        byte[] bytes = Files.readAllBytes(Paths.get(path));
        String image = Base64Util.encode(bytes);
        String imageType = "BASE64";
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("user_top_num", "1");
        //人脸搜索
        JSONObject res = client.search(image, imageType, "yu", options);
        System.out.println(res.toString(2));
    }
}

人脸搜索 请求参数详情
在这里插入图片描述
人脸搜索 返回数据参数详情
在这里插入图片描述
运行控制台输出
score:相识度90

{
  "result": {
    "face_token": "6bca071e248a56e212eedae76a331c34",
    "user_list": [{
      "score": 90.101455688477,
      "group_id": "yu",
      "user_id": "0001",
      "user_info": ""
    }]
  },
  "log_id": 1674136859,
  "error_msg": "SUCCESS",
  "cached": 0,
  "error_code": 0,
  "timestamp": 1707971274
}

换张彭于晏的照片
score:相识度33

{
  "result": {
    "face_token": "a9d9b891693df035877b3c79d271acc6",
    "user_list": [{
      "score": 33.696895599365,
      "group_id": "yu",
      "user_id": "0001",
      "user_info": ""
    }]
  },
  "log_id": 1872494893,
  "error_msg": "SUCCESS",
  "cached": 0,
  "error_code": 0,
  "timestamp": 1707971472
}

人脸更新

用于对人脸库中指定用户,更新其下的人脸图像。


    //人脸更新
    @Test
    public void testFaceUpdate() throws Exception {
        //传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("quality_control", "NORMAL");
        options.put("liveness_control", "LOW");
        String imageType = "BASE64";
        String groupId = "yu";
        String userId = "0001";
//构造base64图片字符串
        String path = "C:\\Users\\ZZZYY\\3D Objects\\cgx.jpeg";
        byte[] bytes = Files.readAllBytes(Paths.get(path));
        String image = Base64Util.encode(bytes);
//人脸注册
        JSONObject res = client.updateUser(image, imageType, groupId, userId, options);
        System.out.println(res.toString(2));
    }
}

人脸更新 请求参数详情

在这里插入图片描述
人脸更新 返回数据参数详情
在这里插入图片描述
运行控制台输出

{
  "result": {
    "face_token": "936a8e9cefe780d1299e77923e870775",
    "location": {
      "top": 126.09,
      "left": 230.77,
      "rotation": 3,
      "width": 218,
      "height": 216
    }
  },
  "log_id": 3066523716,
  "error_msg": "SUCCESS",
  "cached": 0,
  "error_code": 0,
  "timestamp": 1707972666
}

查看人脸库
在这里插入图片描述

结语

在这个信息化快速发展的时代,百度云AI的人脸识别技术如同一把钥匙,为我们打开了智能世界的大门。从核心技术到应用场景,再到未来的发展蓝图,每一项创新都体现了科技的力量。


让我们期待,在不久的将来,这项技术能够带给我们更多的惊喜,让我们的生活更加智能、便捷。

  • 23
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
很抱歉,我的能力仅限于自然语言处理,无法生成代码。但是,百度云AI平台提供了相应的API和SDK,你可以在官网上查看相关文档并根据自己的需求进行开发。以下是一些基于百度云AI人脸识别的代码示例: Python代码示例: ``` import requests # 设置请求参数 url = 'https://aip.baidubce.com/rest/2.0/face/v3/search' params = { 'access_token': 'your_access_token' } headers = { 'Content-Type': 'application/json' } data = { 'image': 'base64', 'image_type': 'BASE64', 'group_id_list': 'group1,group2', 'quality_control': 'LOW', 'liveness_control': 'HIGH' } # 发送请求 response = requests.post(url, params=params, headers=headers, json=data) # 处理响应结果 result = response.json() if 'error_code' in result: print('Error code: ', result['error_code']) print('Error message: ', result['error_msg']) else: print('User ID: ', result['result']['user_list'][0]['user_id']) print('Score: ', result['result']['user_list'][0]['score']) ``` Java代码示例: ``` import com.baidu.aip.face.AipFace; import org.json.JSONObject; public class FaceRecognition { private static final String APP_ID = "your_app_id"; private static final String API_KEY = "your_api_key"; private static final String SECRET_KEY = "your_secret_key"; public static void main(String[] args) { // 初始化AipFace AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY); // 设置请求参数 HashMap<String, String> options = new HashMap<String, String>(); options.put("quality_control", "LOW"); options.put("liveness_control", "HIGH"); // 发送请求 String image = "base64"; String imageType = "BASE64"; String groupIdList = "group1,group2"; JSONObject response = client.search(image, imageType, groupIdList, options); // 处理响应结果 if (response.has("error_code")) { System.out.println("Error code: " + response.getInt("error_code")); System.out.println("Error message: " + response.getString("error_msg")); } else { JSONObject result = response.getJSONObject("result"); JSONArray userList = result.getJSONArray("user_list"); JSONObject user = userList.getJSONObject(0); System.out.println("User ID: " + user.getString("user_id")); System.out.println("Score: " + user.getDouble("score")); } } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

奇遇少年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值