|
|
@@ -7,14 +7,18 @@ import com.arcsoft.face.FaceSimilar;
|
|
|
import com.arcsoft.face.enums.ErrorInfo;
|
|
|
import com.arcsoft.face.toolkit.ImageInfo;
|
|
|
import com.zd.alg.face.config.FaceProperties;
|
|
|
+import com.zd.alg.face.controller.FaceApi;
|
|
|
import com.zd.alg.face.handle.FaceEngineFactory;
|
|
|
import com.zd.common.core.utils.Assert;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+
|
|
|
import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;
|
|
|
|
|
|
/**
|
|
|
@@ -25,12 +29,17 @@ import static com.arcsoft.face.toolkit.ImageFactory.getRGBData;
|
|
|
@Service
|
|
|
public class FaceService {
|
|
|
|
|
|
+ private static Logger logger = LoggerFactory.getLogger(FaceApi.class);
|
|
|
+
|
|
|
@Autowired
|
|
|
FaceEngineFactory faceEngineFactory;
|
|
|
|
|
|
@Autowired
|
|
|
FaceProperties faceProperties;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ FaceEngine faceEngine;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 人脸检测
|
|
|
@@ -39,8 +48,8 @@ public class FaceService {
|
|
|
*/
|
|
|
public List<FaceInfo> faceDetect(ImageInfo imageInfo) {
|
|
|
List<FaceInfo> faceInfoList = new ArrayList<>();
|
|
|
- int errorCode = faceEngineFactory.initFaceEngineImage().detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);
|
|
|
- System.out.println("errorCode:"+errorCode);
|
|
|
+ int errorCode=faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);
|
|
|
+ logger.info("errorCode:"+errorCode);
|
|
|
Assert.isTrue(errorCode == ErrorInfo.MOK.getValue(), "人脸检测失败!");
|
|
|
return faceInfoList;
|
|
|
}
|
|
|
@@ -51,20 +60,13 @@ public class FaceService {
|
|
|
*/
|
|
|
public FaceFeature faceFeature(ImageInfo imageInfo, List<FaceInfo> faceInfoList) {
|
|
|
FaceFeature faceFeature = new FaceFeature();
|
|
|
- FaceEngine imageFaceEngine = null;
|
|
|
- int errorCode;
|
|
|
+ int errorCode = 0;
|
|
|
try {
|
|
|
- imageFaceEngine = faceEngineFactory.initFaceEngineImage();
|
|
|
- errorCode = imageFaceEngine.extractFaceFeature(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList.get(0), faceFeature);
|
|
|
- } finally {
|
|
|
- if (imageFaceEngine != null) {
|
|
|
- imageFaceEngine.unInit();
|
|
|
- }
|
|
|
-
|
|
|
+ errorCode = faceEngine.extractFaceFeature(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList.get(0), faceFeature);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
Assert.isTrue(errorCode == ErrorInfo.MOK.getValue(), "人脸特征提取失败!");
|
|
|
-
|
|
|
return faceFeature;
|
|
|
}
|
|
|
|
|
|
@@ -72,17 +74,12 @@ public class FaceService {
|
|
|
* 人脸对比
|
|
|
*/
|
|
|
public Boolean compore(FaceFeature targetFaceFeature, FaceFeature sourceFaceFeature) {
|
|
|
-
|
|
|
FaceSimilar faceSimilar = new FaceSimilar();
|
|
|
- FaceEngine faceEngine = null;
|
|
|
- int errorCode;
|
|
|
+ int errorCode = 0;
|
|
|
try {
|
|
|
- faceEngine = faceEngineFactory.initFaceEngineImage();
|
|
|
errorCode = faceEngine.compareFaceFeature(targetFaceFeature, sourceFaceFeature, faceSimilar);
|
|
|
- } finally {
|
|
|
- if (faceEngine != null) {
|
|
|
- faceEngine.unInit();
|
|
|
- }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
Assert.isTrue(errorCode == ErrorInfo.MOK.getValue(), "人脸对比失败!");
|
|
|
return faceSimilar.getScore() >= faceProperties.getScore();
|