| 接口地址:https://aip.baidubce.com/rest/2.0/face/v3/faceverify |
|---|
| 返回格式:json |
| 请求方式:post |
| 请求示例:https://aip.baidubce.com/rest/2.0/face/v3/faceverify?access_token=test |
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
| image | string | 必填 | 图片信息(总数据大小应小于10M),图片上传方式根据image_type来判断; 可以上传同一个用户的1张、3张或8张图片来进行活体判断,注:后端会选择每组照片中的最高分数作为整体分数。 |
| image_type | string | 必填 | 图片类型 BASE64:图片的base64值,base64编码后的图片数据,需urlencode,编码后的图片大小不超过2M; URL:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长); FACE_TOKEN: 人脸图片的唯一标识,调用人脸检测接口时,会为每个人脸图片赋予一个唯一的FACE_TOKEN,同一张图片多次检测得到的FACE_TOKEN是同一个。 |
| face_field | string | 选填 | 包括age,beauty,expression,face_shape,gender,glasses,landmark,race,quality,face_type信息,逗号分隔,默认只返回face_token、活体数、人脸框、概率和旋转角度 |
| 名称 | 类型 | 说明 |
|---|---|---|
| face_liveness | float | 活体分数值 |
| thresholds | array | 由服务端返回最新的阈值数据(随着模型的优化,阈值可能会变化),将此参数与返回的face_liveness进行比较,可以作为活体判断的依据。 frr_1e-4:万分之一误识率的阈值;frr_1e-3:千分之一误识率的阈值;frr_1e-2:百分之一误识率的阈值。误识率越低,准确率越高,相应的拒绝率也越高 |
| face_list | array | 每张图片的详细信息描述,如果只上传一张图片,则只返回一个结果。 |
| +face_token | string | 人脸图片的唯一标识 |
| +location | array | 人脸在图片中的位置 |
| ++left | double | 人脸区域离左边界的距离 |
| ++top | double | 人脸区域离上边界的距离 |
| ++width | double | 人脸区域的宽度 |
| ++height | double | 人脸区域的高度 |
| ++rotation | int64 | 人脸框相对于竖直方向的顺时针旋转角,[-180,180] |
| +face_probability | double | 人脸置信度,范围【0~1】,代表这是一张人脸的概率,0最小、1最大。 |
| +angel | array | 人脸旋转角度参数 |
| ++yaw | double | 三维旋转之左右旋转角[-90(左), 90(右)] |
| ++pitch | double | 三维旋转之俯仰角度[-90(上), 90(下)] |
| ++roll | double | 平面内旋转角[-180(逆时针), 180(顺时针)] |
| +age | double | 年龄 ,当<strong>face_field包含age时返回</strong> |
| +beauty | int64 | 美丑打分,范围0-100,越大表示越美。当<strong>face_fields包含beauty时返回</strong> |
| +expression | array | 表情,当 <strong>face_field包含expression时返回</strong> |
| ++type | string | <strong>none</strong>:不笑;<strong>smile</strong>:微笑;<strong>laugh</strong>:大笑 |
| ++probability | double | 表情置信度,范围【0~1】,0最小、1最大。 |
| +face_shape | array | 脸型,当<strong>face_field包含face_shape时返回</strong> |
| ++type | double | <strong>square</strong>: 正方形 <strong>triangle</strong>:三角形 <strong>oval</strong>: 椭圆 <strong>heart</strong>: 心形 <strong>round</strong>: 圆形 |
| ++probability | double | 置信度,范围【0~1】,代表这是人脸形状判断正确的概率,0最小、1最大。 |
| +gender | array | 性别,<strong>face_field包含gender时返回</strong> |
| ++type | string | male:<strong>男性</strong> female:<strong>女性</strong> |
| ++probability | double | 性别置信度,范围【0~1】,0代表概率最小、1代表最大。 |
| +glasses | array | 是否带眼镜,<strong>face_field包含glasses时返回</strong> |
| ++type | string | <strong>none</strong>:无眼镜,<strong>common</strong>:普通眼镜,<strong>sun</strong>:墨镜 |
| ++probability | double | 眼镜置信度,范围【0~1】,0代表概率最小、1代表最大。 |
| +race | array | 人种 <strong>face_field包含race时返回</strong> |
| ++type | string | <strong>yellow</strong>: 黄种人 <strong>white</strong>: 白种人 <strong>black</strong>:黑种人 <strong>arabs</strong>: <strong>阿拉伯人</strong> |
| ++probability | double | 人种置信度,范围【0~1】,0代表概率最小、1代表最大。 |
| +face_type | array | 真实人脸/卡通人脸 <strong>face_field包含face_type时返回</strong> |
| ++type | string | <strong>human</strong>: 真实人脸 <strong>cartoon</strong>: 卡通人脸 |
| ++probability | double | 人脸类型判断正确的置信度,范围【0~1】,0代表概率最小、1代表最大。 |
| +landmark | array | 4个关键点位置,左眼中心、右眼中心、鼻尖、嘴中心。<strong>face_field包含landmark时返回</strong> |
| +landmark72 | array | 72个特征点位置 <strong>face_field包含landmark时返回</strong> |
| +quality | array | 人脸质量信息。<strong>face_field包含quality时返回</strong> |
| ++occlusion | array | 人脸各部分遮挡的概率,范围[0~1],0表示完整,1表示不完整 |
| +++left_eye | double | 左眼遮挡比例,[0-1] , 1表示完全遮挡 |
| +++right_eye | double | 右眼遮挡比例,[0-1] , 1表示完全遮挡 |
| +++nose | double | 鼻子遮挡比例,[0-1] , 1表示完全遮挡 |
| +++mouth | double | 嘴巴遮挡比例,[0-1] , 1表示完全遮挡 |
| +++left_cheek | double | 左脸颊遮挡比例,[0-1] , 1表示完全遮挡 |
| +++right_cheek | double | 右脸颊遮挡比例,[0-1] , 1表示完全遮挡 |
| +++chin | double | 下巴遮挡比例,,[0-1] , 1表示完全遮挡 |
| ++blur | double | 人脸模糊程度,范围[0~1],0表示清晰,1表示模糊 |
| ++illumination | double | 取值范围在[0~255], 表示脸部区域的光照程度 越大表示光照越好 |
| ++completeness | int64 | 人脸完整度,0或1, 0为人脸溢出图像边界,1为人脸都在图像边界内 |
{
"thresholds": {
"frr_1e-4": 0.05, //万分之一误拒率的阈值
"frr_1e-3": 0.3, //千分之一误拒率的阈值
"frr_1e-2": 0.9 //百分之一误拒率的阈值
},
"face_liveness": 0.05532243927,
"face_list": [{
"face_token": "df46f7c7db4aa09a093c26fb8d1a8d44",
"location": {
"left": 328.9026489,
"top": 97.16340637,
"width": 162,
"height": 154,
"rotation": 32
},
"face_probability": 1,
"angle": {
"yaw": 10.16196251,
"pitch": 2.244354248,
"roll": 33.82199097
},
"age": 23,
"beauty": 20.23693275
},
{
"face_token": "901d2c64274fccd687d311a6e6110a01",
"location": {
"left": 411.4876404,
"top": 166.3593445,
"width": 329,
"height": 308,
"rotation": 45
},
"face_probability": 0.9194830656,
"angle": {
"yaw": -1.716423035,
"pitch": 7.344647408,
"roll": 45.79914856
},
"age": 23,
"beauty": 12.6438179
},
{
"face_token": "7d57e36981c48b4946eb97c8d838b02a",
"location": {
"left": 161.4559937,
"top": 199.8726501,
"width": 218,
"height": 201,
"rotation": -1
},
"face_probability": 1,
"angle": {
"yaw": -8.187754631,
"pitch": 6.973727226,
"roll": -1.25429821
},
"age": 23,
"beauty": 8.20657444
}
]
}| 错误码 | 说明 |
|---|---|
| 4 | 集群超限额 |
| 6 | 没有接口权限 |
| 17 | 每天流量超限额 |
| 18 | QPS超限额 |
| 19 | 请求总量超限额 |
| 100 | 无效的access_token参数 |
| 110 | Access Token失效 |
| 111 | Access token过期 |
| 222001 | 必要参数未传入 |
| 222002 | 参数格式错误 |
| 222003 | 参数格式错误 |
| 222004 | 参数格式错误 |
| 222005 | 参数格式错误 |
| 222006 | 参数格式错误 |
| 222007 | 参数格式错误 |
| 222008 | 参数格式错误 |
| 222009 | 参数格式错误 |
| 222010 | 参数格式错误 |
| 222011 | 参数格式错误 |
| 222012 | 参数格式错误 |
| 222013 | 参数格式错误 |
| 222014 | 参数格式错误 |
| 222015 | 参数格式错误 |
| 222016 | 参数格式错误 |
| 222017 | 参数格式错误 |
| 222018 | 参数格式错误 |
| 222019 | 参数格式错误 |
| 222020 | 参数格式错误 |
| 222021 | 参数格式错误 |
| 222022 | 参数格式错误 |
| 222023 | 参数格式错误 |
| 222024 | 参数格式错误 |
| 222025 | 参数格式错误 |
| 222026 | 参数格式错误 |
| 222027 | 验证码长度错误<br>(最小值大于最大值) |
| 222028 | 参数格式错误 |
| 222029 | 参数格式错误 |
| 222030 | 参数格式错误 |
| 222200 | 该接口需使用<br>application/json的<br>格式进行请求 |
| 222201 | 服务端请求失败 |
| 222202 | 图片中没有人脸 |
| 222203 | 无法解析人脸 |
| 222204 | 从图片的url下载<br>图片失败 |
| 222205 | 服务端请求失败 |
| 222206 | 服务端请求失败 |
| 222207 | 未找到匹配的用户 |
| 222208 | 图片的数量错误 |
| 222209 | face token不存在 |
| 222210 | 人脸库中用户下的人脸数目超过限制 |
| 222300 | 人脸图片添加失败 |
| 222301 | 获取人脸图片失败 |
| 222302 | 服务端请求失败 |
| 222303 | 获取人脸图片失败 |
| 223100 | 操作的用户组不存在 |
| 223101 | 该用户组已存在 |
| 223102 | 该用户已存在 |
| 223103 | 找不到该用户 |
| 223104 | group_list包含组<br>数量过多 |
| 223105 | 该人脸已存在 |
| 223106 | 该人脸不存在 |
| 223110 | uid_list包含数量过多 |
| 223111 | 目标用户组不存在 |
| 223112 | quality_conf格式不正确 |
| 223113 | 人脸有被遮挡 |
| 223114 | 人脸模糊 |
| 223115 | 人脸光照不好 |
| 223116 | 人脸不完整 |
| 223117 | app_list包含app数量<br>过多 |
| 223118 | 质量控制项错误 |
| 223119 | 活体控制项错误 |
| 223120 | 活体检测未通过 |
| 223121 | 质量检测未通过 左眼<br>遮挡程度过高 |
| 223122 | 质量检测未通过 右眼<br>遮挡程度过高 |
| 223123 | 质量检测未通过 左脸<br>遮挡程度过高 |
| 223124 | 质量检测未通过 右脸<br>遮挡程度过高 |
| 223125 | 质量检测未通过 下巴遮挡程度过高 |
| 223126 | 质量检测未通过 鼻子遮挡程度过高 |
| 223127 | 质量检测未通过 嘴巴<br>遮挡程度过高 |
| 222901 | 参数校验初始化失败 |
| 222902 | 参数校验初始化失败 |
| 222903 | 参数校验初始化失败 |
| 222904 | 参数校验初始化失败 |
| 222905 | 接口初始化失败 |
| 222906 | 接口初始化失败 |
| 222907 | 缓存处理失败 |
| 222908 | 缓存处理失败 |
| 222909 | 缓存处理失败 |
| 222910 | 数据存储处理失败 |
| 222911 | 数据存储处理失败 |
| 222912 | 数据存储处理失败 |
| 222913 | 接口初始化失败 |
| 222914 | 接口初始化失败 |
| 222915 | 后端服务连接失败 |
| 222916 | 后端服务连接失败 |
| 222304 | 图片尺寸太大 |
| 223128 | 正在清理该用户组的数据 |
| 222361 | 公安服务连接失败 |
在线活体检测
curl -i -k 'https://aip.baidubce.com/rest/2.0/face/v3/faceverify?access_token=【调用鉴权接口获取的token】' --data '[{"image":"sfasq35sadvsvqwr5q...","image_type":"BASE64","face_field":"age,beauty,expression"},{"image":"http://xxx.baidu.com/image1.png","image_type":"URL","face_field":"age,beauty"}]' -H 'Content-Type:application/json; charset=UTF-8'<?php
/**
* 发起http post请求(REST API), 并获取REST请求的结果
* @param string $url
* @param string $param
* @return - http response body if succeeds, else false.
*/
function request_post($url = '', $param = '')
{
if (empty($url) || empty($param)) {
return false;
}
$postUrl = $url;
$curlPost = $param;
// 初始化curl
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $postUrl);
curl_setopt($curl, CURLOPT_HEADER, 0);
// 要求结果为字符串且输出到屏幕上
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
// post提交方式
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
// 运行curl
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
$token = '[调用鉴权接口获取的token]';
$url = 'https://aip.baidubce.com/rest/2.0/face/v3/faceverify?access_token=' . $token;
$bodys = "[{\"image\":\"sfasq35sadvsvqwr5q...\",\"image_type\":\"BASE64\",\"face_field\":\"age,beauty,expression\"},{\"image\":\"http://xxx.baidu.com/image1.png\",\"image_type\":\"URL\",\"face_field\":\"age,beauty\"}]"
$res = request_post($url, $bodys);
var_dump($res);package com.baidu.ai.aip;
import com.baidu.ai.aip.utils.HttpUtil;
import com.baidu.ai.aip.utils.GsonUtils;
import java.util.*;
/**
* 在线活体检测
*/
public class FaceVerify {
/**
* 重要提示代码中所需工具类
* FileUtil,Base64Util,HttpUtil,GsonUtils请从
* https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
* https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
* https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
* https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
* 下载
*/
public static String faceVerify() {
// 请求url
String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceverify";
try {
String param = GsonUtils.toJson(map);
// 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
String accessToken = "[调用鉴权接口获取的token]";
String result = HttpUtil.post(url, accessToken, "application/json", param);
System.out.println(result);
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
FaceVerify.faceVerify();
}
}# encoding:utf-8
import urllib
import urllib2
'''
在线活体检测
'''
request_url = "https://aip.baidubce.com/rest/2.0/face/v3/faceverify"
params = "[{\"image\":\"sfasq35sadvsvqwr5q...\",\"image_type\":\"BASE64\",\"face_field\":\"age,beauty,expression\"},{\"image\":\"http://xxx.baidu.com/image1.png\",\"image_type\":\"URL\",\"face_field\":\"age,beauty\"}]"
access_token = '[调用鉴权接口获取的token]'
request_url = request_url + "?access_token=" + access_token
request = urllib2.Request(url=request_url, data=params)
request.add_header('Content-Type', 'application/json')
response = urllib2.urlopen(request)
content = response.read()
if content:
print content#include <iostream>
#include <curl/curl.h>
// libcurl库下载链接:https://curl.haxx.se/download.html
// jsoncpp库下载链接:https://github.com/open-source-parsers/jsoncpp/
const static std::string request_url = "https://aip.baidubce.com/rest/2.0/face/v3/faceverify";
static std::string faceVerify_result;
/**
* curl发送http请求调用的回调函数,回调函数中对返回的json格式的body进行了解析,解析结果储存在全局的静态变量当中
* @param 参数定义见libcurl文档
* @return 返回值定义见libcurl文档
*/
static size_t callback(void *ptr, size_t size, size_t nmemb, void *stream) {
// 获取到的body存放在ptr中,先将其转换为string格式
faceVerify_result = std::string((char *) ptr, size * nmemb);
return size * nmemb;
}
/**
* 在线活体检测
* @return 调用成功返回0,发生错误返回其他错误码
*/
int faceVerify(std::string &json_result, const std::string &access_token) {
std::string url = request_url + "?access_token=" + access_token;
CURL *curl = NULL;
CURLcode result_code;
int is_success;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.data());
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type:application/json;charset=UTF-8");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "[{\"image\":\"sfasq35sadvsvqwr5q...\",\"image_type\":\"BASE64\",\"face_field\":\"age,beauty,expression\"},{\"image\":\"http://xxx.baidu.com/image1.png\",\"image_type\":\"URL\",\"face_field\":\"age,beauty\"}]");
result_code = curl_easy_perform(curl);
if (result_code != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s
",
curl_easy_strerror(result_code));
is_success = 1;
return is_success;
}
json_result = faceVerify_result;
curl_easy_cleanup(curl);
is_success = 0;
} else {
fprintf(stderr, "curl_easy_init() failed.");
is_success = 1;
}
return is_success;
}using System;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
namespace com.baidu.ai
{
public class FaceVerify
{
// 在线活体检测
public static string faceVerify()
{
string token = "[调用鉴权接口获取的token]";
string host = "https://aip.baidubce.com/rest/2.0/face/v3/faceverify?access_token=" + token;
Encoding encoding = Encoding.Default;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(host);
request.Method = "post";
request.KeepAlive = true;
String str = "[{\"image\":\"sfasq35sadvsvqwr5q...\",\"image_type\":\"BASE64\",\"face_field\":\"age,beauty,expression\"},{\"image\":\"http://xxx.baidu.com/image1.png\",\"image_type\":\"URL\",\"face_field\":\"age,beauty\"}]";
byte[] buffer = encoding.GetBytes(str);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
string result = reader.ReadToEnd();
Console.WriteLine("在线活体检测:");
Console.WriteLine(result);
return result;
}
}
}