Android-SDK-v2.0说明
版本日志
版本 | 日期 | 更新说明 |
---|---|---|
v2.0.3 | 2019.06.14 | 1、更新硬件指纹获取模块,优化特殊环境下指纹变更的问题 |
v2.0.2 | 2019.04.01 | 1、全新人脸检测模型,检测追踪更流畅; 2、全新证件照模型:体积更小,速度更快 ; 3、部分接口细节优化 |
v2.0.1 | 2019.03.14 | 1、接口设计优化; 2、增加几款结构光镜头支持; 3、已知bug修复 |
v2.0.0 | 2019.01.10 | 1、优化生活照模型精度及速度 2、优化检测模型及策略 3、优化接口设计 4、优化活体检测速度 |
v1.1.0 | 2018.09.03 | 1、增加离线证件照特征抽取模型,可有效处理芯片照、证件照比对需求 2、增加离线人脸属性模型,支持性别、年龄等属性分析 3、增加多线程支持 4、增加离线激活支持,可导入授权文件无网激活 5、增加对奥比中光Astra Pro深度图镜头模组支持 6、增加对华捷艾米深度镜头模组支持 7、其他细节优化及已知bug修复 |
v1.0.1 | 2018.08.03 | 1、修复设备指纹发生变化bug 2、替换近红外活体模型,优化效果 3、修复批量注册人脸到人脸库,失败问题 4、修复注册、图片人脸检测、视频返回图片抽取特征失败,经常出现检测不到人脸问题 |
v1.0.0 | 2018.06.29 | 初版,包括离线人脸采集、离线活体检测、离线对比识别、离线人脸库管理等功能 |
目录
11、FaceAuth-鉴权接口
2 1.1 鉴权-在线授权
3 1.2 鉴权-SDK 压缩文件,本地鉴权
4 1.3 开启底层Log输出
5 1.4 设置Anakin核数
62、FaceDetect-检测接口
7 2.1 检测对齐模型加载
8 2.2 质量检测模型加载
9 2.3 配置信息加载
10 2.4 YUV图片转换ARGB
11 2.5 人脸框检测
12 2.6 人脸跟踪-最大人脸接口
13 2.7 人脸跟踪-第一个人脸接口
14 2.8 人脸跟踪-多人脸检测
15 2.9 人脸图像质量检测
16 2.10 检测方法类型设置
17 2.11 人脸图片信息清理
183、FaceLive-活体接口
19 3.1 活体模型加载
20 3.2 人脸静默活体检测-RGB可见光
21 3.3 人脸静默活体检测-NIR近红外或Depth深度图
224、FaceFeature-特征接口
23 4.1 特征模型加载
24 4.2 人脸特征提取
25 4.3 人脸特征比对
265、FaceAttributes-属性接口
27 5.1 属性情绪模型加载
28 5.2 人脸属性检测
29 5.3 人脸表情检测
306、人脸信息实体类
31 6.1 基础信息实体类
32 6.2 扩展信息实体类
1、FaceAuth鉴权接口
1.1 鉴权-在线授权
说明:用户通过申请授权码,在线授权,激活设备
1void initLicenseOnLine(final Context context, final String licenseKey, final AuthCallback callback)
参数名 | 含义 |
---|---|
context | 当前上下文 |
licenseKey | AIPE 鉴权码 |
callback | 鉴权结果 void onResponse(int code, String response) code 0 : 成功;code 1 加载失败 response 结果信息 |
1.2 鉴权-SDK 压缩文件,本地鉴权
说明:用户通过申请鉴权文件,存储在SD 卡根目录下,离线鉴权,激活设备
1void initLicenseOffLine(final Context context, final AuthCallback callback)
参数名 | 含义 |
---|---|
context | 当前上下文 |
callback | 鉴权结果 void onResponse(int code, String response) code 0 : 成功;code 1 加载失败 response 结果信息 |
1.3 开启底层Log输出
说明:用于Debug 时候输出LOG 详细信息
1void setActiveLog(BDFaceLogInfo logInfo)
参数名 | 含义 |
---|---|
BDFaceLogInfo | 底层log 打印 BDFACE_LOG_VALUE_MESSAGE, // 打印输出值日志 BDFACE_LOG_ERROR_MESSAGE, // 打印输出错误日志 BDFACE_LOG_ALL_MESSAGE, // 打印所有日志 |
1.4 设置Anakin核数
说明:根据开发板类型,设置加速对Cpu 核数依赖,调整参数,提高性能
1void setAnakinThreadsConfigure(int flagsThreads ,int flagsCluster)
参数名 | 含义 |
---|---|
flagsThreads | 大核个数(建议:3288传入2,3399传入4) |
flagsCluster | 小核个数(建议:传入0) |
2、FaceDetect检测接口
2.1 检测对齐模型加载
说明:检测模型加载,目前支持可见光模型,近红外检测模型(非必要参数,可以为空),对齐模型
1void initModel(final Context context, final String visModel,final String nirModel,final String alignModel, final Callback callback)
参数名 | 含义 |
---|---|
context | 上下文context |
visModel | 可见光图片检测模型 |
nirModel | 红外图片检测模型(非必要参数,可以为空) |
alignModel | 对齐类型 |
callback | 模型加载结果 void onResponse(int code, String response) code 0 : 成功;code 1 加载失败 response 结果信息 |
2.2 质量检测模型加载
说明:质量检测模型加载,判断人脸遮挡信息,光照信息,模糊信息,模型包含模糊模型,遮挡信息,作用于质量检测接口
1void initQuality(final Context context, final String blurModel, final String occlurModel, final Callback callback)
参数名 | 含义 |
---|---|
context | 上下文context |
blurModel | 模糊检测模型 |
occlurModel | 遮挡检测模型 |
callback | 鉴权结果 void onResponse(int code, String response) code 0 : 成功;code 1 加载失败 response 结果信息 |
2.3 配置信息加载
说明:检测最小人脸,是否开启内部质量检测,检测或者追踪时间间隔等配置
1void loadConfig(BDFaceSDKConfig config)
参数名 | 含义 |
---|---|
config | 参数配置实体 |
2.4 YUV图片转换ARGB
说明:摄像头回调数据格式转化,YUV 转为ARGB 用于检测
1int getDataFromYUVimg(byte[] dataYUV, int[] imageData, int width, int height, int angle, int flip)
参数名 | 含义 |
---|---|
dataYUV | YUV 图片字节数 |
imageData | RGBA 图片返回值 |
width | 图片宽 |
height | 图片高 |
angle | 原图的旋转角度 |
flip | 原图是否镜像(0 非镜像 1 镜像) |
2.5 人脸框检测
说明:人脸框检测,每一帧图片都会检测,返回基本人脸信息,可以人脸框绘制
1FaceInfo[] detect(int[] imageData, int height, int width,int minFaceSize)
参数名 | 含义 |
---|---|
imageData | ARGB图片像素点 |
height | 图片高 |
width | 图片宽 |
minFaceSize | 需要检测的最小人脸尺寸 |
返回 |
---|
成功则返回 FaceInfo[] 数组,包含:人脸框width,人脸angle,人脸框中心坐标x,y,人脸可信度mConf |
1 if (faceDetect == null) {
2 Toast.makeText(mContext,
3 "未初始化检测模型", Toast.LENGTH_SHORT).show();
4 return;
5 }
6 faceDetect.setDetectMethodType(FaceDetect.DetectType.DETECT_VIS);
7 FaceInfo[] faceInfos = faceDetect.detect(
8 liveVisImg.data, liveVisImg.height, liveVisImg.width, 50);
9 if (faceInfos != null && faceInfos.length > 0) {
10 FaceInfo faceInfo = faceInfos[0];
11 StringBuilder info = new StringBuilder();
12 info.append("face info length:").append(faceInfos.length)
13 .append(" face_id:").append(faceInfo.face_id)
14 .append(" width:").append(faceInfo.mWidth)
15 .append(" score:").append(faceInfo.mConf);
16 Toast.makeText(mContext,
17 info,
18 Toast.LENGTH_SHORT).show();
19 Log.e("handler", info.toString());
20 } else {
21 String info = " face info length 0";
22 Toast.makeText(mContext,
23 info, Toast.LENGTH_SHORT).show();
24 Log.e("handler", info);
25 }
2.6 人脸跟踪-最大人脸接口
说明:人脸跟踪检测,追踪图片中最大人脸信息,接口包含检测和跟踪功能,返回基本人脸信息和72 关键点,可以绘制人脸框,描绘眼耳鼻嘴关键点,也可作用于后续活体,特征抽取入参。
1FaceInfo[] trackMaxFace(int[] imageData, int height, int width)
参数名 | 含义 |
---|---|
imageData | ARGB图片像素点 |
height | 图片高 |
width | 图片宽 |
返回 |
---|
成功则返回 FaceInfo[] 数组,包含:人脸框width,人脸angle,人脸框中心坐标x,y,人脸可信度mConf,72个关键点landmark,人脸face_id,三个姿态角度headPose,动作活体数据is_live,用户根据自己需求选择 |
1 if (faceDetect == null) {
2 Toast.makeText(mContext,
3 "未初始化检测模型", Toast.LENGTH_SHORT).show();
4 return;
5 }
6 faceDetect.setDetectMethodType(FaceDetect.DetectType.DETECT_VIS);
7 FaceInfo[] faceInfos = faceDetect.trackMaxFace(
8 liveVisImg.data, liveVisImg.height, liveVisImg.width
9 );
10 if (faceInfos != null && faceInfos.length > 0) {
11 FaceInfo faceInfo = faceInfos[0];
12 StringBuilder info = new StringBuilder();
13 info.append("face info length:").append(faceInfos.length)
14 .append(" face_id:").append(faceInfo.face_id)
15 .append(" width:").append(faceInfo.mWidth)
16 .append(" score:").append(faceInfo.mConf);
17 if (faceInfo.occlu != null && faceInfo.occlu.length == 7) {
18 info.append("face occlusion: ")
19 .append(" L eye:").append(faceInfo.occlu[0])
20 .append(" R eye:").append(faceInfo.occlu[1])
21 .append(" nose:").append(faceInfo.occlu[2])
22 .append(" mouth:").append(faceInfo.occlu[3])
23 .append(" L contour:").append(faceInfo.occlu[4])
24 .append(" R contour:").append(faceInfo.occlu[5])
25 .append(" chin contour:").append(faceInfo.occlu[6]);
26 info.append("face blur: ").append(faceInfo.blur);
27 info.append("face illum: ").append(faceInfo.illum);
28 }
29 Toast.makeText(mContext,
30 info,
31 Toast.LENGTH_SHORT).show();
32 Log.e("handler", info.toString());
33 } else {
34 String info = " face info length 0";
35 Toast.makeText(mContext,
36 info, Toast.LENGTH_SHORT).show();
37 Log.e("handler", info);
38 }
39 faceDetect.clearTrackedFaces();
2.7 人脸跟踪-第一个人脸接口
说明:人脸跟踪检测,追踪图片中第一个人脸信息,接口包含检测和跟踪功能,返回基本人脸信息和72 关键点,可以绘制人脸框,描绘眼耳鼻嘴关键点,也可作用于后续活体,特征抽取入参。
1FaceInfo[] trackFirstFace(int[] imageData, int height, int width)
参数名 | 含义 |
---|---|
imageData | ARGB图片像素点 |
height | 图片高 |
width | 图片宽 |
返回 |
---|
成功则返回 FaceInfo[] 数组,包含:人脸框width,人脸angle,人脸框中心坐标x,y,人脸可信度mConf,72个关键点landmark,人脸face_id,三个姿态角度headPose,动作活体数据is_live,用户根据自己需求选择 |
2.8 人脸跟踪-多人脸检测
说明:人脸跟踪检测,追踪图片中多个人脸信息,通过参数num 配置,接口包含检测和跟踪功能,返回基本人脸信息和72 关键点,可以绘制人脸框,描绘眼耳鼻嘴关键点,也可作用于后续活体,特征抽取入参。
1FaceInfo[] track(int[] imageData, int height, int width, int num)
参数名 | 含义 |
---|---|
imageData | ARGB图片像素点 |
height | 图片高 |
width | 图片宽 |
num | 最大跟踪人脸个数 |
返回 |
---|
成功则返回 FaceInfo[] 数组,包含:人脸框width,人脸angle,人脸框中心坐标x,y,人脸可信度mConf,72个关键点landmark,人脸face_id,三个姿态角度headPose,动作活体数据is_live,用户根据自己需求选择 |
2.9 人脸图像质量检测
说明:单个原子方法质量检测方法(也可以配置BDFaceSDKConfig 中的 isCheckBlur 等三个参数,在trackMaxFace 和 trackFirstFace 方法内部生效)
1int imgQuality(int[] imageData, int height, int width, int[] landmarks,float[] bluriness, int[] illum, float[] occlusion, int[] nOccluPart)
参数名 | 含义 |
---|---|
imageData | 图片像素点 |
height | 图片高 |
width | 图片宽 |
landmark | 人脸72个关键点FaceInfo.landmark |
bluriness | 模糊结果 |
illum | 光照结果 |
occlusion | 遮挡结果 |
nOccluPart | 遮挡部位 |
返回 |
---|
成功则返回 1 |
1 if (faceDetect == null) {
2 Toast.makeText(mContext,
3 "未初始化检测模型", Toast.LENGTH_SHORT).show();
4 return;
5 }
6 faceDetect.setDetectMethodType(FaceDetect.DetectType.DETECT_VIS);
7 FaceInfo[] faceInfos = faceDetect.trackMaxFace(
8 liveVisImg.data, liveVisImg.height, liveVisImg.width);
9 if (faceInfos != null && faceInfos.length > 0) {
10 FaceInfo faceInfo = faceInfos[0];
11 // 质量检测通过加入人脸列表
12 float[] bluriness = new float[1];
13 int[] illum = new int[1];
14 float[] occlusion = new float[7];
15 int[] nOccluPart = new int[1];
16 faceDetect.imgQuality(liveVisImg.data, liveVisImg.height,
17 liveVisImg.width, faceInfo.landmarks, bluriness, illum, occlusion, nOccluPart);
18 StringBuilder info = new StringBuilder();
19 info.append("face occlusion: ")
20 .append(" L eye:").append(occlusion[0])
21 .append(" R eye:").append(occlusion[1])
22 .append(" nose:").append(occlusion[2])
23 .append(" mouth:").append(occlusion[3])
24 .append(" L contour:").append(occlusion[4])
25 .append(" R contour:").append(occlusion[5])
26 .append(" chin contour:").append(occlusion[6]);
27 info.append("face blur: ").append(bluriness[0]);
28 info.append("face illum: ").append(illum[0]);
29 Toast.makeText(mContext,
30 info,
31 Toast.LENGTH_SHORT).show();
32 Log.e("handler", info.toString());
33 } else {
34 String info = " face info length 0";
35 Toast.makeText(mContext,
36 info, Toast.LENGTH_SHORT).show();
37 Log.e("handler", info);
38 }
39 faceDetect.clearTrackedFaces();
2.10 检测方法类型设置
说明:检测方法类型设置,建议FACEBOX_VIS 可见光检测
1void setDetectMethodType(DetectType detectMethodType)
参数名 | 含义 |
---|---|
detectMethodType | 图片检测类型(目前两种支持FACEBOX_VIS和FACEBOX_NIR,建议FACEBOX_VIS 可见光检测) |
2.11 人脸图片信息清理
说明:清空trackMaxFace 和 trackFirstFace 接口检测缓存数据,在注册或者识别成功之后,可以调用该接口
1void clearTrackedFaces()
3、FaceLive活体接口
3.1 活体模型加载
说明:静默活体检测模型初始化,可见光活体模型,近红外活体模型,深度活体模型初始化
1void initModel(final Context context,final String visModel,final String nirModel,final String depthModel,final Callback callback)
参数名 | 含义 |
---|---|
context | 上下文context |
visModel | 可见光图片活体模型 |
nirModel | 红外图片活体模型 |
depthModel | 深度图活体模型 |
callback | 模型加载结果 void onResponse(int code, String response) code 0 : 成功;code 1 加载失败 response 结果信息 |
3.2 人脸静默活体检测-RGB可见光
说明:可见光静默活体分值检测,返回0-1结果,建议超过0.9 为活体
1float silentLive(LiveType liveType, int[] imageData, int height, int width, int[] landmarks)
参数名 | 含义 |
---|---|
liveType | FaceLive.LiveType.LIVEID_VIS 可见光图像静默活体检测<br / |
imageData | ARGB图片像素点 |
height | 图片高 |
width | 图片宽 |
landmark | 人脸72个关键点FaceInfo.landmark |
返回 |
---|
成功则返回活体分值 |
1 if (faceDetect == null) {
2 Toast.makeText(mContext,
3 "未初始化检测模型", Toast.LENGTH_SHORT).show();
4 return;
5 }
6
7 if (faceLive == null) {
8 Toast.makeText(mContext,
9 "未初始化活体模型", Toast.LENGTH_SHORT).show();
10 return;
11 }
12 faceDetect.setDetectMethodType(FaceDetect.DetectType.DETECT_VIS);
13
14 FaceInfo[] faceInfos = faceDetect.trackMaxFace(
15 liveVisImg.data, liveVisImg.height, liveVisImg.width
16 );
17
18 if (faceInfos != null && faceInfos.length > 0) {
19 FaceInfo faceInfo = faceInfos[0];
20
21 float visScore = faceLive.silentLive(FaceLive.LiveType.LIVEID_VIS,
22 liveVisImg.data, liveVisImg.height, liveVisImg.width,
23 faceInfo.landmarks);
24 float nirScore = faceLive.silentLive(FaceLive.LiveType.LIVEID_NIR,
25 liveVisImg.dataByte, liveVisImg.height, liveVisImg.width,
26 faceInfo.landmarks);
27 float depthScore = faceLive.silentLive(FaceLive.LiveType.LIVEID_DEPTH,
28 liveDepthImg.dataByte, liveVisImg.height, liveVisImg.width,
29 faceInfo.landmarks);
30 StringBuilder builder = new StringBuilder();
31 builder.append("live-vis").append(visScore)
32 .append(" live-nir").append(nirScore)
33 .append(" live-depth").append(depthScore);
3.3 人脸静默活体检测-NIR近红外或Depth深度图
说明:近红外和深度静默活体分值检测,返回0-1结果,建议超过0.9 为活体;红外和深度为byte 字节数组
1float silentLive(LiveType liveType, byte[] imageData, int height, int width, int[] landmarks)
参数名 | 含义 |
---|---|
liveType | FaceLive.LiveType.LIVEID_NIR近红外图像静默活体检测 FaceLive.LiveType.LIVEID_DEPTH 深度图静默活体检测 |
imageData | 灰度图片像素点或深度图片像素点 |
height | 图片高 |
width | 图片宽 |
landmark | 人脸72个关键点FaceInfo.landmark |
返回 |
---|
成功则返回活体分值 |
4、FaceFeature特征接口
4.1 特征模型加载
说明:离线特征获取模型加载,目前支持可见光模型,近红外检测模型(非必要参数,可以为空),证件照模型;用户根据自己场景,选择相应场景模型
1initModel(final Context context,final String idPhotoModel,final String visModel,final String nirModel,final Callback callback)
参数名 | 含义 |
---|---|
context | 上下文context |
idPhotoModel | 证件照图片模型 |
visModel | 可见光图片模型 |
nirModel | 红外图片模型(非必要参数,可以为空) |
callback | 模型加载结果 void onResponse(int code, String response) code 0 : 成功;code 1 加载失败 response 结果信息 |
4.2 人脸特征提取
说明:离线特征提取接口,通过featureType 提取不同图片特征数据,函数返回特征个数,特征存储在feature 参数中
1float feature(FeatureType featureType, int[] imageData, int height, int width, int[] landmarks, byte[] feature)
参数名 | 含义 |
---|---|
featureType | FeatureType.FEATURE_VIS生活照 FeatureType.FEATURE_ID_PHOTO证件照照 |
imageData | 图片像素点 |
height | 图片高 |
width | 图片宽 |
landmark | 人脸72个关键点FaceInfo.landmark |
feature | 人脸特征 feature 数组,默认初始化512空字节 |
返回 |
---|
成功则返回512 特征点 |
1 if (faceDetect == null) {
2 Toast.makeText(mContext,
3 "未初始化检测模型", Toast.LENGTH_SHORT).show();
4 return;
5 }
6
7 if (faceFeature == null) {
8 Toast.makeText(mContext,
9 "未初始化特征模型", Toast.LENGTH_SHORT).show();
10 return;
11 }
12 faceDetect.setDetectMethodType(FaceDetect.DetectType.DETECT_VIS);
13
14 FaceInfo[] faceInfos = faceDetect.trackMaxFace(
15 featureIdPImg.data, featureIdPImg.height, featureIdPImg.width
16 );
17
18 byte[] feature1 = new byte[512];
19 if (faceInfos != null && faceInfos.length > 0) {
20 FaceInfo faceInfo = faceInfos[0];
21 float length = faceFeature.feature(FaceFeature.FeatureType.FEATURE_VIS,
22 featureIdPImg.data, featureIdPImg.height, featureIdPImg.width, faceInfo.landmarks, feature1);
23 Log.e("handler", "VIS feature 1 length " + length);
24 }
25 faceDetect.clearTrackedFaces();
26
27 FaceInfo[] faceInfos2 = faceDetect.trackMaxFace(
28 featureVisImg.data, featureVisImg.height, featureVisImg.width
29 );
30
31 byte[] feature2 = new byte[512];
32 if (faceInfos2 != null && faceInfos2.length > 0) {
33 FaceInfo faceInfo2 = faceInfos2[0];
34 float length = faceFeature.feature(FaceFeature.FeatureType.FEATURE_VIS,
35 featureVisImg.data, featureVisImg.height, featureVisImg.width, faceInfo2.landmarks, feature2);
36 Log.e("handler", "VIS feature 2 length " + length);
37 }
38 faceDetect.clearTrackedFaces();
39
40 float result = faceFeature.featureCompare(FaceFeature.FeatureType.FEATURE_VIS,
41 feature1, feature2);
4.3 人脸特征比对
说明:离线特征比对结果,分值为0--100 之间
1float featureCompare(FeatureType featureType, byte[] feature1, byte feature2)
参数名 | 含义 |
---|---|
featureType | FeatureType.FEATURE_VIS生活照 FeatureType.FEATURE_ID_PHOTO证件照照 |
feature1 | 特征1 |
feature2 | 特征2 |
返回 |
---|
成功则返回 比对结果(0--100) |
5、FaceAttributes属性接口
5.1 属性情绪模型加载
说明:人脸属性(年龄,性别,戴眼镜等),情绪(喜怒哀乐)模型初始化
1void initModel(final Context context,final String atttibuteModel,final String emotionModel,final Callback callback)
参数名 | 含义 |
---|---|
context | 上下文context |
atttibuteModel | 属性模型 |
emotionModel | 情绪模型 |
callback | 模型加载结果 void onResponse(int code, String response) code 0 : 成功;code 1 加载失败 response 结果信息 |
5.2 人脸属性检测
说明:获取人脸属性信息,包含年龄,表情,种族,性别,是否佩戴眼镜
1BDFaceSDKAttribute attribute(int[] imageData, int height, int width, int[] landmarks)
参数名 | 含义 |
---|---|
imageData | ARGB图片像素点 |
height | 图片高 |
width | 图片宽 |
landmark | 人脸72个关键点FaceInfo.landmark |
返回 |
---|
成功则返回 BDFaceSDKAttribute |
1 if (faceDetect == null) {
2 Toast.makeText(mContext,
3 "未初始化检测模型", Toast.LENGTH_SHORT).show();
4 return;
5 }
6
7 if (faceAttributes == null) {
8 Toast.makeText(mContext,
9 "未初始化属性模型", Toast.LENGTH_SHORT).show();
10 return;
11 }
12
13 faceDetect.setDetectMethodType(FaceDetect.DetectType.DETECT_VIS);
14
15 FaceInfo[] faceInfos = faceDetect.trackMaxFace(
16 liveVisImg.data, liveVisImg.height, liveVisImg.width);
17
18 if (faceInfos != null && faceInfos.length > 0) {
19 FaceInfo faceInfo = faceInfos[0];
20 BDFaceSDKAttribute attribute = faceAttributes.attribute(liveVisImg.data,
21 liveVisImg.height, liveVisImg.width,
22 faceInfo.landmarks);
23
24 BDFaceSDKEmotions emotions = faceAttributes.emotions(liveVisImg.data,
25 liveVisImg.height, liveVisImg.width,
26 faceInfo.landmarks);
27
28 final StringBuilder builder = new StringBuilder();
29 if (attribute != null) {
30 builder.append(" attribute:");
31 builder.append(attribute.age);
32 builder.append(" ").append(attribute.emotion);
33 builder.append(" ").append(attribute.gender);
34 builder.append(" ").append(attribute.glasses);
35 }
36 if (emotions != null) {
37 builder.append("\n emotion:");
38 builder.append(" ").append(emotions.emotion);
39 builder.append(" ").append(emotions.expression_conf);
40 }
41 Log.e("handler", "attribute " + builder.toString());
42
43 }
44 faceDetect.clearTrackedFaces();
5.3 人脸表情检测
说明:获取人脸表情信息,包含生气,开心,厌恶,害怕,惊讶等
1BDFaceSDKEmotions emotions(int[] imageData, int height, int width, int[] landmarks)
参数名 | 含义 |
---|---|
imageData | ARGB图片像素点 |
height | 图片高 |
width | 图片宽 |
landmark | 人脸72个关键点FaceInfo.landmark |
返回 |
---|
成功则返回BDFaceSDKEmotions |
6、人脸信息实体类
6.1 基础信息实体类
1/**
2 * 人脸信息实体类
3 */
4
5public class FaceInfo {
6 public float mWidth; // rectangle width
7 public float mAngle; // rectangle tilt angle [-45 45] in degrees
8 public float mCenter_y; // rectangle center y
9 public float mCenter_x; // rectangle center x
10 public float mConf; // face detection score
11
12 public int[] landmarks;
13 public int face_id;
14 public float[] headPose;
15 public int[] is_live;
16
17 public float illum = 0f;
18 public float blur = 0f;
19 public float[] occlu;
20
21 public FaceInfo(float width, float angle, float y, float x, float conf) {
22 mWidth = width;
23 mAngle = angle;
24 mCenter_y = y;
25 mCenter_x = x;
26 mConf = conf;
27 landmarks = null;
28 face_id = 0;
29 }
30
31 public FaceInfo(float width, float angle, float y, float x, float conf, int track_id, int[] ldmks) {
32 mWidth = width;
33 mAngle = angle;
34 mCenter_y = y;
35 mCenter_x = x;
36 mConf = conf;
37 landmarks = ldmks;
38 face_id = track_id;
39 }
40
41 public FaceInfo(float width, float angle, float y, float x, float conf,
42 int track_id, int[] ldmks, float[] pose, int[] livestatus,
43 float illum,float blur,float[] occlu
44 ) {
45 mWidth = width;
46 mAngle = angle;
47 mCenter_y = y;
48 mCenter_x = x;
49 mConf = conf;
50 landmarks = ldmks;
51 face_id = track_id;
52 headPose = pose;
53 is_live = livestatus;
54 this.illum = illum;
55 this.blur = blur;
56 this.occlu = occlu;
57 }
58}
6.2 扩展信息实体类
1// 图片信息类
2public class BDFaceSDKImageInfo {
3 public int height; // 图片高度
4 public int widht; // 图片宽度
5 public int[] data; // 图片数据
6 public BDFaceSDKCommon.BDFaceImageType type; // 图片格式
7
8 public BDFaceSDKImageInfo(int height, int widht, int[] data, int type) {
9 this.height = height;
10 this.widht = widht;
11 this.data = data;
12 this.type = BDFaceSDKCommon.BDFaceImageType.values()[type];
13 }
14}
15
16public class BDFaceSDKConfig {
17 /**
18 * 最小人脸检测大小 建议50
19 */
20 public int minFaceSize = 50;
21
22 /**
23 * 最大人脸检测大小 建议-1(不做限制)
24 */
25 public int maxFaceSize = -1;
26
27 /**
28 * 人脸跟踪,检测的时间间隔 默认 500ms
29 */
30 public int trackInterval = 0;
31
32 /**
33 * 人脸跟踪,跟踪时间间隔 默认 1000ms
34 */
35 public int detectInterval = 0;
36
37 /**
38 * 人脸置信度阈值,建议值0.5
39 */
40 public float noFaceSize = 0.5f;
41
42 /**
43 * 人脸姿态角 pitch,yaw,roll
44 */
45 public int pitch;
46 public int yaw;
47 public int roll;
48
49 /**
50 * 质量检测模糊,遮挡,光照,默认不做质量检测
51 */
52 public boolean isCheckBlur = true;
53 public boolean isOcclusion = true;
54 public boolean isIllumination = true;
55
56 /**
57 * 检测图片类型,可见光或者红外
58 */
59 public FaceDetect.DetectType detectMethodType
60 = FaceDetect.DetectType.DETECT_VIS;
61}
62
63// 人脸属性
64public class BDFaceSDKAttribute {
65 public int age; // 年龄
66 public BDFaceSDKCommon.BDFaceRace race; // 种族
67 public BDFaceSDKCommon.BDFaceEmotion emotion; // 表情
68 public BDFaceSDKCommon.BDFaceGlasses glasses; // 戴眼镜状态
69 public BDFaceSDKCommon.BDFaceGender gender; // 性别
70
71 public BDFaceSDKAttribute(int age, int race, int emotion, int glasses, int gender) {
72 this.age = age;
73 this.race = BDFaceSDKCommon.BDFaceRace.values()[race];
74 this.emotion = BDFaceSDKCommon.BDFaceEmotion.values()[emotion];
75 this.gender = BDFaceSDKCommon.BDFaceGender.values()[gender];
76 this.glasses = BDFaceSDKCommon.BDFaceGlasses.values()[glasses];
77 }
78}
79
80// 人脸情绪
81public class BDFaceSDKEmotions {
82 public BDFaceSDKCommon.BDFaceEmotionEnum emotion;
83 public float expression_conf;
84 public float[] expression_conf_list;
85
86 public BDFaceSDKEmotions(int emotion, float expression_conf, float[] expression_conf_list) {
87 this.emotion = BDFaceSDKCommon.BDFaceEmotionEnum.values()[emotion];
88 this.expression_conf = expression_conf;
89 this.expression_conf_list = expression_conf_list;
90 }
91}
92 // 图像类型
93 public enum BDFaceImageType {
94 BD_FACE_IMAGE_TYPE_RGB, // rgb图像
95 BD_FACE_IMAGE_TYPE_BGR, // bgr图像
96 BD_FACE_IMAGE_TYPE_RGBA, // rgba图像
97 BD_FACE_IMAGE_TYPE_BGRA, // bgra图像
98 BD_FACE_IMAGE_TYPE_GRAY, // 灰度图
99 BD_FACE_IMAGE_TYPE_DEPTH, // 深度图
100 BD_FACE_IMAGE_TYPE_YUV422, // YUV422图像
101 BD_FACE_IMAGE_TYPE_YUV_411, // YUV 411图像
102 BD_FACE_IMAGE_TYPE_YUV_420, // YUV 411图像
103 BD_FACE_IMAGE_TYPE_YUV_YUYV, // YUV YUYV图像
104 BD_FACE_IMAGE_TYPE_YUV_YU12, // YUV YU12图像
105 BD_FACE_IMAGE_TYPE_YUV_NV12, // YUV NV12图像
106 BD_FACE_IMAGE_TYPE_YUV_NV21, // YUV NV21图像
107 }
108
109 // 表情类型
110 public enum BDFaceEmotion {
111 BDFACE_EMOTION_NEUTRAL, // 中性表情
112 BDFACE_EMOTION_SMILE, // 微笑
113 BDFACE_EMOTION_BIG_SMILE, // 大笑
114 }
115
116 // 情绪
117 public enum BDFaceEmotionEnum {
118 BDFACE_EMOTIONS_ANGRY, // 生气
119 BDFACE_EMOTIONS_DISGUST, // 恶心
120 BDFACE_EMOTIONS_FEAR, // 害怕
121 BDFACE_EMOTIONS_HAPPY, // 开心
122 BDFACE_EMOTIONS_SAD, // 伤心
123 BDFACE_EMOTIONS_SURPRISE, // 惊讶
124 BDFACE_EMOTIONS_NEUTRAL, // 无情绪
125 };
126
127 // 人脸属性种族
128 public enum BDFaceRace {
129 BDFACE_RACE_YELLOW, // 黄种人
130 BDFACE_RACE_WHITE, // 白种人
131 BDFACE_RACE_BLACK, // 黑种人
132 BDFACE_RACE_INDIAN, // 印度人
133 }
134
135 // 戴眼镜状态
136 public enum BDFaceGlasses {
137 BDFACE_NO_GLASSES, // 无眼镜
138 BDFACE_GLASSES, // 有眼镜
139 BDFACE_SUN_GLASSES, // 墨镜
140 }
141
142 // 性别
143 public enum BDFaceGender {
144 BDFACE_GENDER_FEMALE, // 女性
145 BDFACE_GENDER_MALE, // 男性
146 }
147 /**
148 * log种类枚举
149 */
150 public enum BDFaceLogInfo {
151 BDFACE_LOG_VALUE_MESSAGE, // 打印输出值日志
152 BDFACE_LOG_ERROR_MESSAGE, // 打印输出错误日志
153 BDFACE_LOG_ALL_MESSAGE, // 打印所有日志
154 };