项目地址
前期准备
攻击人脸判断也叫活体判断
- 在介绍人脸识别很关键的人脸跟踪和质量评估之前,先看一个对应用很重要的活体检测模块。
- 关于活体检测模块的重要程度和原因,这里不做过多赘述,这里直接给出SeetaFace的活体检测方案。
- 活体检测结合了两个方法,全局活体检测和局部活体检测。
- 全局活体检测就是对图片整体做检测,主要是判断是否出现了活体检测潜在的攻击介质,如手机、平板、照片等等。
- 局部活体检测是对具体人脸的成像细节通过算法分析,区别是一次成像和二次成像,如果是二次成像则认为是出现了攻击。
攻击人脸检测代码
package com.seeta.sdk.proxy;
import com.seeta.pool.SeetaConfSetting;
import com.seeta.proxy.AgePredictorProxy;
import com.seeta.proxy.FaceAntiSpoofingProxy;
import com.seeta.proxy.FaceDetectorProxy;
import com.seeta.proxy.FaceLandmarkerProxy;
import com.seeta.sdk.*;
import com.seeta.sdk.util.LoadNativeCore;
import com.seeta.sdk.util.SeetafaceUtil;
/**
* 活体检测,攻击人脸检测
*/
public class FaceAntiSpoofingProxyTest {
//模型文件夹路径
public static String CSTA_PATH = "E:\\models";
//图片路径
public static String fileName = "E:\\111.jpg";
// 拼接模型路径
public static String[] detector_cstas = {CSTA_PATH + "/face_detector.csta"};
// 人脸关键点定位模型路径拼接
public static String[] landmarker_cstas = {CSTA_PATH + "/face_landmarker_pts5.csta"};
//活体检测模型,两个
public static String[] fas = {CSTA_PATH + "/fas_first.csta",CSTA_PATH + "/fas_second.csta"};
//加载dll
static {
LoadNativeCore.LOAD_NATIVE(SeetaDevice.SEETA_DEVICE_AUTO);
}
public static void main(String[] args) {
//人脸识别检测器对象池配置,可以配置对象的个数哦
SeetaConfSetting detectorPoolSetting = new SeetaConfSetting(new SeetaModelSetting(0, detector_cstas, SeetaDevice.SEETA_DEVICE_AUTO));
//人脸检测器对象池代理 , spring boot可以用FaceDetectorProxy来配置Bean
FaceDetectorProxy faceDetectorProxy = new FaceDetectorProxy(detectorPoolSetting);
//人脸关键点定位器对象池配置
SeetaConfSetting faceLandmarkerPoolSetting = new SeetaConfSetting(new SeetaModelSetting(0, landmarker_cstas, SeetaDevice.SEETA_DEVICE_AUTO));
//人脸关键点定位器对象池代理 , spring boot可以用FaceLandmarkerProxy来配置Bean
FaceLandmarkerProxy faceLandmarkerProxy = new FaceLandmarkerProxy(faceLandmarkerPoolSetting);
SeetaConfSetting faceAntiSpoofingSetting = new SeetaConfSetting(new SeetaModelSetting(0, fas, SeetaDevice.SEETA_DEVICE_AUTO));
FaceAntiSpoofingProxy faceAntiSpoofingProxy = new FaceAntiSpoofingProxy(faceAntiSpoofingSetting);
try {
SeetaImageData image = SeetafaceUtil.toSeetaImageData(fileName);
SeetaRect[] detects = faceDetectorProxy.detect(image);
for (SeetaRect seetaRect : detects) {
SeetaPointF[] pointFS = faceLandmarkerProxy.mark(image, seetaRect);
FaceAntiSpoofing.Status predict = faceAntiSpoofingProxy.predict(image,seetaRect, pointFS);
//输出
System.out.println(predict);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
输出结果
- FaceAntiSpoofing.Status:
REAL, //< 真实人脸
SPOOF, //< 攻击人脸(假人脸)
FUZZY, //< 无法判断(人脸成像质量不好)
DETECTING, //< 正在检测
结果:REAL
总结
1. 人脸识别过程复杂,但这个代码简单。
2. 精度高,这边的模型都是中科院商业开源的,比起社区的模型,用到的训练集多很多。
3. 功能齐全 :
人脸检测和关键点定位
人脸特征提取和对比
人脸特征提取
人脸特征对比
活体检测
人脸跟踪
质量评估
年龄识别
性别识别
口罩检测
口罩人脸识别
眼睛状态检测