- swan.ai.faceDetect
- 方法参数
- object 参数说明
- success 返回参数说明
- result 参数说明
- face_list 参数说明
- location 返回值说明
- angel 返回值说明
- expression 返回值说明
- face_shape 返回值说明
- gender 返回值说明
- glasses 返回值说明
- eye_status 返回值说明
- emotion 返回值说明
- race 返回值说明
- face_type 返回值说明
- landmark 返回值说明
- quality 返回值说明
- occlusion 返回值说明
- 示例
- 图片示例
- 代码示例 1:image_type 为 BASE64
- 代码示例 2:image_type 为 URL
- 代码示例 3:image_type 为 FACE_TOKEN
- 返回值示例
- 方法参数
swan.ai.faceDetect
基础库 3.20.11 开始支持,低版本需做兼容处理。
解释:人脸检测,检测图片中的人脸并标记出相应的信息位置,同时可以展示出人脸的关键信息和属性信息,比如年龄,性别等。使用本功能需要小程序开发者后台登录超级管理员账号,点击云平台付费链接开通云账号付费功能。
Web 态说明:受宿主环境限制,Web 态暂不支持 AI 能力相关接口。在 Web 态会做 打开百度 App 对应小程序页面 的降级处理。
方法参数
Object object
object 参数说明
属性名 | 类型 | 必填 | 默认值 | 说明 |
---|---|---|---|---|
image |
String |
是 |
图片信息(总数据大小应小于 10M),图片上传方式根据 image_type 来判断。注意: |
|
image_type |
String |
是 |
图片类型。有效值: |
|
face_field |
String |
否 |
包括 age、beauty、expression、face_shape、gender、glasses、landmark、race、quality、eye_status、emotion、face_type 信息,逗号分隔。默认只返回 face_token 、人脸框、概率和旋转角度 |
|
max_face_num |
String |
否 |
1 |
最多处理人脸的数目,默认值为 1 ,仅检测图片中面积最大的那个人脸;最大值 10 ,检测图片中面积最大的几张人脸 |
face_type |
String |
否 |
LIVE |
人脸的类型。有效值: |
success |
Function |
否 |
接口调用成功后的回调函数 |
|
fail |
Function |
否 |
接口调用失败的回调函数 |
|
complete |
Function |
否 |
接口调用结束的回调函数(调用成功、失败都会执行) |
success 返回参数说明
参数名 | 参数类型 | 说明 |
---|---|---|
log_id |
Number |
唯一的 log id ,用于问题定位 |
error_code |
Number |
错误码,错误码为 0 时,人脸检测成功 |
error_msg |
String |
错误描述信息,帮助理解和解决发生的错误 |
result |
Object |
人脸属性对象的集合 |
result 参数说明
参数名 | 参数类型 | 说明 |
---|---|---|
face_num |
Number |
检测到图片中的人脸数量 |
face_list |
Array |
人脸信息列表 |
face_list 参数说明
参数名 | 参数类型 | 说明 |
---|---|---|
face_token |
String |
人脸图片的唯一标识 |
location |
Object |
人脸在图片中的位置 |
face_probability |
Number |
人脸置信度,范围 [0-1] ,代表这是一张人脸的概率,0:最小、1:最大 |
angel |
Object |
人脸旋转角度参数 |
age |
Number |
年龄,当 face_field 包含 age 时返回 |
beauty |
Number |
美丑打分,范围 [0-100],越大表示越美,当 face_fields 包含 beauty 时返回 |
expression |
Object |
表情,当 face_field 包含 expression 时返回 |
face_shape |
Object |
脸型,当 face_field 包含 face_shape 时返回 |
gender |
Object |
性别,face_field 包含 gender 时返回 |
glasses |
Object |
是否带眼镜,face_field 包含 glasses 时返回 |
eye_status |
Object |
双眼状态(睁开/闭合)face_field 包含 eye_status 时返回 |
emotion |
Object |
情绪,face_field 包含 emotion 时返回 |
race |
Object |
人种 face_field 包含 race 时返回 |
face_type |
Object |
真实人脸/卡通人脸 face_field 包含 face_type 时返回 |
landmark |
Object |
4 个关键点位置,左眼中心、右眼中心、鼻尖、嘴中心。face_field 包含 landmark 时返回 |
quality |
Object |
人脸质量信息,face_field 包含 quality 时返回 |
location 返回值说明
参数名 | 参数类型 | 说明 |
---|---|---|
left |
Number |
人脸区域离左边界的距离 |
top |
Number |
人脸区域离上边界的距离 |
width |
Number |
人脸区域的宽度 |
height |
Number |
人脸区域的高度 |
rotation |
Number |
人脸框相对于竖直方向的顺时针旋转角,[-180,180] |
angel 返回值说明
参数名 | 参数类型 | 说明 |
---|---|---|
yaw |
Number |
三维旋转之左右旋转角 [-90(左),90(右)] |
pitch |
Number |
三维旋转之俯仰角度 [-90(上),90(下)] |
roll |
Number |
平面内旋转角 [-180(逆时针),180(顺时针)] |
expression 返回值说明
参数名 | 参数类型 | 说明 |
---|---|---|
type |
String |
none:不笑;smile:微笑;laugh:大笑 |
probability |
Number |
表情置信度,范围 [0-1] ,0 最小、1 最大 |
face_shape 返回值说明
参数名 | 参数类型 | 说明 |
---|---|---|
type |
String |
square:正方形;triangle:三角形;oval:椭圆;heart:心形;round:圆形 |
probability |
Number |
置信度,范围 [0-1] ,代表这是人脸形状判断正确的概率,0 最小、1 最大 |
gender 返回值说明
参数名 | 参数类型 | 说明 |
---|---|---|
type |
String |
male:男性;female:女性 |
probability |
Number |
性别置信度,范围 [0-1] ,0 代表概率最小、1 代表最大 |
glasses 返回值说明
参数名 | 参数类型 | 说明 |
---|---|---|
type |
String |
none:无眼镜;common:普通眼镜;sun:墨镜 |
probability |
Number |
眼镜置信度,范围 [0-1],0 代表概率最小、1 代表最大 |
eye_status 返回值说明
参数名 | 参数类型 | 说明 |
---|---|---|
left_eye |
Number |
左眼状态 [0,1] 取值,越接近 0 闭合的可能性越大 |
right_eye |
Number |
右眼状态 [0,1] 取值,越接近 0 闭合的可能性越大 |
emotion 返回值说明
参数名 | 参数类型 | 说明 |
---|---|---|
type |
String |
angry:愤怒;disgust:厌恶;fear:恐惧;happy:高兴;sad:伤心;surprise:惊讶;neutral:无情绪 |
probability |
Number |
情绪置信度,范围 [0-1] |
race 返回值说明
参数名 | 参数类型 | 说明 |
---|---|---|
type |
String |
yellow:黄种人;white:白种人;black:黑种人;arabs:阿拉伯人 |
probability |
Number |
人种置信度,范围 [0-1] ,0:代表概率最小、1:代表最大 |
face_type 返回值说明
参数名 | 参数类型 | 说明 |
---|---|---|
type |
String |
human:真实人脸;cartoon:卡通人脸 |
probability |
Number |
人脸类型判断正确的置信度,范围 [0-1] ,0:代表概率最小、1:代表最大 |
landmark 返回值说明
参数名 | 参数类型 | 说明 |
---|---|---|
landmark72 |
Array |
72 个特征点位置 face_field 包含 landmark72 时返回 |
landmark150 |
Array |
150 个特征点位置 face_field 包含 landmark150 时返回 |
quality 返回值说明
参数名 | 参数类型 | 说明 |
---|---|---|
occlusion |
Number |
人脸各部分遮挡的概率,范围 [0-1] ,0:表示完整,1:表示不完整 |
blur |
Number |
人脸模糊程度,范围 [0-1] ,0:表示清晰,1:表示模糊 |
illumination |
Number |
取值范围在 [0-255] ,表示脸部区域的光照程度越大表示光照越好 |
completeness |
Number |
人脸完整度,0 或 1 ,0:为人脸溢出图像边界,1:为人脸都在图像边界内 |
occlusion 返回值说明
参数名 | 参数类型 | 说明 |
---|---|---|
left_eye |
Number |
左眼遮挡比例,[0-1] ,1:表示完全遮挡 |
right_eye |
Number |
右眼遮挡比例,[0-1] ,1:表示完全遮挡 |
nose |
Number |
鼻子遮挡比例,[0-1] ,1:表示完全遮挡 |
left_cheek |
Number |
左脸颊遮挡比例,[0-1] ,1:表示完全遮挡 |
right_cheek |
Number |
右脸颊遮挡比例,[0-1] ,1:表示完全遮挡 |
chin |
Number |
下巴遮挡比例,[0-1] ,1:表示完全遮挡 |
示例
扫码体验
代码示例
请使用百度APP扫码
图片示例
代码示例 1:image_type 为 BASE64
在开发者工具中打开
在开发者工具中打开
在 WEB IDE 中打开
- JS
Page({
faceDetect() {
swan.chooseImage({
success: res => {
let image = res.tempFilePaths[0];
// AI系列的api有宿主使用限制,只可在百度App中使用,建议使用时加一层判断防止代码报未知错误
let host = swan.getSystemInfoSync().host;
if (host === 'baiduboxapp') {
swan.ai.faceDetect({
image,
image_type: 'BASE64',
face_field: 'age,beauty,angle,expression,face_shape,gender,glasses,eye_status,race,quality',
max_face_num: '1',
face_type: 'LIVE',
success: res => {
console.log(res.face_list);
},
fail: err => {
console.log( err);
}
});
}
else {
swan.showToast({
title: '此api目前仅可在百度App上使用',
icon: 'none'
});
}
}
})
}
});
代码示例 2:image_type 为 URL
在开发者工具中打开
在开发者工具中打开
在 WEB IDE 中打开
- JS
Page({
faceDetect() {
swan.chooseImage({
success: res => {
let image = res.tempFilePaths[0];
// AI系列的api有宿主使用限制,只可在百度App中使用,建议使用时加一层判断防止代码报未知错误
let host = swan.getSystemInfoSync().host;
if (host === 'baiduboxapp') {
swan.ai.faceDetect({
image:'https://b.bdstatic.com/miniapp/image/faceDetect.png',
image_type: 'URL',
face_field: 'age,beauty,angle,expression,face_shape,gender,glasses,eye_status,race,quality',
max_face_num: '1',
face_type: 'LIVE',
success: res => {
console.log(res.face_list);
},
fail: err => {
console.log( err);
}
});
}
else {
swan.showToast({
title: '此api目前仅可在百度App上使用',
icon: 'none'
});
}
}
})
}
});
代码示例 3:image_type 为 FACE_TOKEN
在开发者工具中打开
在开发者工具中打开
在 WEB IDE 中打开
- JS
Page({
faceDetect() {
swan.chooseImage({
success: res => {
let image = res.tempFilePaths[0];
// AI系列的api有宿主使用限制,只可在百度App中使用,建议使用时加一层判断防止代码报未知错误
let host = swan.getSystemInfoSync().host;
if (host === 'baiduboxapp') {
swan.ai.faceDetect({
// 可由之前图片检测的返回值中获得
image:'4160b708a826b18de95fe5c9a098a436',
image_type: 'FACE_TOKEN',
face_field: 'age,beauty,angle,expression,face_shape,gender,glasses,eye_status,race,quality',
max_face_num: '1',
face_type: 'LIVE',
success: res => {
console.log(res.face_list);
},
fail: err => {
console.log( err);
}
});
}
else {
swan.showToast({
title: '此api目前仅可在百度App上使用',
icon: 'none'
});
}
}
})
}
});
返回值示例
- JSON
{
"face_num": 1,
"face_list": [
{
"face_token": "35235asfas21421fakghktyfdgh68bio",
"location": {
"left": 117,
"top": 131,
"width": 172,
"height": 170,
"rotation": 4
},
"face_probability": 1,
"angle" :{
"yaw" : -0.34859421849251
"pitch" 1.9135693311691
"roll" :2.3033397197723
}
"landmark": [
{
"x": 161.74819946289,
"y": 163.30244445801
},
...
],
"landmark72": [
{
"x": 115.86531066895,
"y": 170.0546875
},
...
],
"age": 29.298097610474,
"beauty": 55.128883361816,
"expression": {
"type": "smile",
"probability" : 0.5543018579483
},
"gender": {
"type": "male",
"probability": 0.99979132413864
},
"glasses": {
"type": "sun",
"probability": 0.99999964237213
},
"race": {
"type": "yellow",
"probability": 0.99999976158142
},
"face_shape": {
"type": "triangle",
"probability": 0.5543018579483
}
"quality": {
"occlusion": {
"left_eye": 0,
"right_eye": 0,
"nose": 0,
"mouth": 0,
"left_cheek": 0.0064102564938366,
"right_cheek": 0.0057411273010075,
"chin": 0
},
"blur": 1.1886881756684e-10,
"illumination": 141,
"completeness": 1
}
}
]
}