刷脸登录是基于人工智能、生物识别、3D传感、大数据风控技术,最新实现的登录形式。用户在无需输入用户名
密码的前提下,凭借“刷脸”完成登录过程。实现刷脸登录的核心是人脸处理,在人脸处理中有两个概念:
人脸检测:检测图中的人脸,并为人脸标记出边框。检测出人脸后,可对人脸进行分析,获得眼、口、鼻轮
廓等72个关键点定位准确识别多种人脸属性,如性别,年龄,表情等信息
人脸识别(对比):通过提取人脸的特征,计算两张人脸的相似度,从而判断是否同一个人,并给出相似度
评分
注册:
注册百度云帐号
打开百度云平台:https://login.bce.baidu.com/reg.html?tpl=bceplat&from=portal进行账号注册
记住: AppID,API Key,Secret Key
环境搭建
人脸注册:
//人脸注册
@Test
public void testFaceRegister() throws Exception {
//传入可选参数调用接口
HashMap
options.put("quality_control", "NORMAL"); //图片质量控制
options.put("liveness_control", "LOW"); //活体检测控制
String imageType = "BASE64";
String groupId = "groupId ";
String userId = "userId ";
//构造base64图片字符串
String path = "C:\\Users\\001.png";
byte[] bytes = Files.readAllBytes(Paths.get(path));
String image = Base64Util.encode(bytes);
// 人脸注册
JSONObject result = client.addUser(image, imageType, groupId, userId, options);
}
人脸注册 请求参数详情
image:图片信息(总数据大小应小于10M),图片上传方式根据image_type来判断
image_type:图片类型 BASE64:图片的base64值,base64编码后的图片数据,需urlencode,编码后的图片大小不超过2M;URL:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长);FACE_TOKEN: 人脸图片的唯一标识,调用人脸检测接口时,会为每个人脸图片赋予一个唯一的FACE_TOKEN,同一张图片多次检测得到的FACE_TOKEN是同一个
group_id:用户组id(由数字、字母、下划线组成),长度限制128B
user_id:用户id(由数字、字母、下划线组成),长度限制128B
user_info:用户资料,长度限制256B
quality_control:图片质量控制 NONE: 不进行控制 LOW:较低的质量要求NORMAL: 一般的质量要求 HIGH: 较高的质量要求 默认NONE
liveness_control:活体检测控制 NONE: 不进行控制 LOW:较低的活体要求(高通过率 低攻击拒绝率) NORMAL: 一般的活体要求(平衡的攻击拒绝率, 通过率) HIGH: 较高的活体要求(高攻击拒绝率 低通过率) 默认NONE
人脸注册返回参数:
人脸更新
//人脸更新
@Test
public void testFaceUpdate() throws Exception {
//传入可选参数调用接口
HashMap
options.put("quality_control", "NORMAL");
options.put("liveness_control", "LOW");
String imageType = "BASE64";
String groupId = "groupId";
String userId = "userId";
//构造base64图片字符串
String path = "C:\\Users\\000.png";
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));
}
人脸检测
//人脸检测
@Test
public void testFaceDetect() throws IOException {
String path = "C:\\Users\\002.png";
byte[] bytes = Files.readAllBytes(Paths.get(path));
String image = Base64Util.encode(bytes);
String imageType = "BASE64";
HashMap
subOptions.put("max_face_num", "10");
//人脸检测
JSONObject res = client.detect(image, imageType, subOptions);
System.out.println(res.toString(2));
}
请求参数:
返回参数:
人脸查找
//人脸搜索
@Test
public void testFaceSearch() throws IOException {
String path = "D:\\223.png";
byte[] bytes = Files.readAllBytes(Paths.get(path));
String image = Base64Util.encode(bytes);
String imageType = "BASE64";
HashMap
options.put("user_top_num", "1");
//人脸搜索
JSONObject res = client.search(image, imageType, "itcast", options);
System.out.println(res.toString(2));
}
---------------------
作者:单人影i
来源:CSDN
原文:https://blog.csdn.net/a185589690/article/details/89528393
版权声明:本文为博主原创文章,转载请附上博文链接!