项目地址
前期准备
人脸遮挡评估代码
package com.seeta.sdk.proxy;
import com.seeta.pool.SeetaConfSetting;
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;
import java.util.Arrays;
/**
* 使用对象池
* 人脸遮挡评估测试
*/
public class LandmarkerProxyTest {
//模型文件夹路径
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[] face_landmarker_mask_pts5_cstas = {CSTA_PATH + "/face_landmarker_mask_pts5.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, face_landmarker_mask_pts5_cstas, SeetaDevice.SEETA_DEVICE_AUTO));
//人脸关键点定位器对象池代理 , spring boot可以用FaceLandmarkerProxy来配置Bean
FaceLandmarkerProxy faceLandmarkerProxy = new FaceLandmarkerProxy(faceLandmarkerPoolSetting);
try {
//图片
SeetaImageData image = SeetafaceUtil.toSeetaImageData(fileName);
//检测人脸,识别到人脸
SeetaRect[] detects = faceDetectorProxy.detect(image);
for (SeetaRect seetaRect : detects) {
//人脸关键点定位,人脸遮挡的点位
LandmarkerMask mask = faceLandmarkerProxy.isMask(image, seetaRect);
//输出
System.out.println(Arrays.toString(mask.getSeetaPointFS()));
System.out.println(Arrays.toString(mask.getMasks()));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
输出结果
- 结果1表示定位到的关键点,五个关键点,分别是左右眼中心、鼻尖和左右嘴角
- 结果2表示关键点有没有被遮挡,1:遮挡, 0:没遮挡
结果1:[SeetaPointF{x=229.45148932933807, y=198.19792396594858}, SeetaPointF{x=339.58734488487244, y=203.27415060797102}, SeetaPointF{x=275.9813448190689, y=265.7534281641201}, SeetaPointF{x=243.33962106704712, y=305.1243141249979}, SeetaPointF{x=314.47644221782684, y=307.86544809458064}]
结果2:[0, 0, 1, 1, 1]
总结
1. 人脸识别过程复杂,但这个代码简单。
2. 精度高,这边的模型都是中科院商业开源的,比起社区的模型,用到的训练集多很多。
3. 功能齐全 :
人脸检测和关键点定位
人脸特征提取和对比
人脸特征提取
人脸特征对比
活体检测
人脸跟踪
质量评估
年龄识别
性别识别
口罩检测
口罩人脸识别
眼睛状态检测