|
@@ -1,15 +1,13 @@
|
|
|
-package com.zd.alg.face.controller;
|
|
|
|
|
|
|
+package com.zd.alg.face;
|
|
|
|
|
|
|
|
import com.arcsoft.face.FaceFeature;
|
|
import com.arcsoft.face.FaceFeature;
|
|
|
import com.arcsoft.face.FaceInfo;
|
|
import com.arcsoft.face.FaceInfo;
|
|
|
import com.arcsoft.face.toolkit.ImageInfo;
|
|
import com.arcsoft.face.toolkit.ImageInfo;
|
|
|
-import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
|
|
|
|
-import com.zd.alg.face.service.FaceService;
|
|
|
|
|
-import com.zd.alg.face.utils.FileUtil;
|
|
|
|
|
-import com.zd.algorithm.api.face.feign.FaceCompare;
|
|
|
|
|
|
|
+import com.zd.model.entity.FaceCompare;
|
|
|
import com.zd.common.core.utils.DateUtils;
|
|
import com.zd.common.core.utils.DateUtils;
|
|
|
import com.zd.common.core.utils.StringUtils;
|
|
import com.zd.common.core.utils.StringUtils;
|
|
|
-import com.zd.common.swagger.config.Knife4jConfiguration;
|
|
|
|
|
|
|
+import com.zd.common.core.utils.file.FileUtils;
|
|
|
|
|
+import com.zd.common.face.FaceRecognitionService;
|
|
|
import com.zd.laboratory.api.entity.LabStudentsInfo;
|
|
import com.zd.laboratory.api.entity.LabStudentsInfo;
|
|
|
import com.zd.laboratory.api.entity.LabSysUserInfo;
|
|
import com.zd.laboratory.api.entity.LabSysUserInfo;
|
|
|
import com.zd.laboratory.api.feign.RemoteDutyService;
|
|
import com.zd.laboratory.api.feign.RemoteDutyService;
|
|
@@ -24,7 +22,6 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.concurrent.*;
|
|
import java.util.concurrent.*;
|
|
@@ -37,22 +34,18 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
@Api(tags = "【人脸识别】")
|
|
@Api(tags = "【人脸识别】")
|
|
|
-@ApiSupport(author = Knife4jConfiguration.Author.ZP)
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/faceApi")
|
|
@RequestMapping("/faceApi")
|
|
|
public class FaceApi {
|
|
public class FaceApi {
|
|
|
|
|
|
|
|
- //private static final ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
|
|
|
|
|
-
|
|
|
|
|
private static final int taskSize = 50;
|
|
private static final int taskSize = 50;
|
|
|
|
|
|
|
|
private static ExecutorService pool = Executors.newFixedThreadPool(taskSize);
|
|
private static ExecutorService pool = Executors.newFixedThreadPool(taskSize);
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
private Logger logger = LoggerFactory.getLogger(FaceApi.class);
|
|
private Logger logger = LoggerFactory.getLogger(FaceApi.class);
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private FaceService faceService;
|
|
|
|
|
|
|
+ private FaceRecognitionService faceService;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RemoteStudentsService remoteStudentsService;
|
|
private RemoteStudentsService remoteStudentsService;
|
|
@@ -66,7 +59,7 @@ public class FaceApi {
|
|
|
ImageInfo imageInfo;
|
|
ImageInfo imageInfo;
|
|
|
File file1 = null;
|
|
File file1 = null;
|
|
|
try {
|
|
try {
|
|
|
- file1 = FileUtil.multipartFileToFile(file);
|
|
|
|
|
|
|
+ file1 = FileUtils.multipartFileToFile(file);
|
|
|
imageInfo = faceService.getImageInfo(file1);
|
|
imageInfo = faceService.getImageInfo(file1);
|
|
|
} finally {
|
|
} finally {
|
|
|
if (file1 != null) {
|
|
if (file1 != null) {
|
|
@@ -87,7 +80,7 @@ public class FaceApi {
|
|
|
public ResultData detectFaces(@RequestParam("file") MultipartFile file) throws IOException {
|
|
public ResultData detectFaces(@RequestParam("file") MultipartFile file) throws IOException {
|
|
|
File fileToFile = null;
|
|
File fileToFile = null;
|
|
|
try {
|
|
try {
|
|
|
- fileToFile = FileUtil.multipartFileToFile(file);
|
|
|
|
|
|
|
+ fileToFile = FileUtils.multipartFileToFile(file);
|
|
|
ImageInfo imageInfo = faceService.getImageInfo(fileToFile);
|
|
ImageInfo imageInfo = faceService.getImageInfo(fileToFile);
|
|
|
List<FaceInfo> faceInfos = faceService.faceDetect(imageInfo);
|
|
List<FaceInfo> faceInfos = faceService.faceDetect(imageInfo);
|
|
|
if(null==faceInfos || faceInfos.size()==0){
|
|
if(null==faceInfos || faceInfos.size()==0){
|
|
@@ -110,15 +103,13 @@ public class FaceApi {
|
|
|
@ApiOperation("人脸比较")
|
|
@ApiOperation("人脸比较")
|
|
|
@PostMapping("/compare")
|
|
@PostMapping("/compare")
|
|
|
public ResultData faceDetection(@RequestBody FaceCompare faceCompare) {
|
|
public ResultData faceDetection(@RequestBody FaceCompare faceCompare) {
|
|
|
- logger.info("====人脸比较====");
|
|
|
|
|
R<LabStudentsInfo> info = remoteStudentsService.getInfo(faceCompare.getUserId());
|
|
R<LabStudentsInfo> info = remoteStudentsService.getInfo(faceCompare.getUserId());
|
|
|
if (info.getCode() == 200 && info.getData() != null) {
|
|
if (info.getCode() == 200 && info.getData() != null) {
|
|
|
- logger.info("====人脸data组装====");
|
|
|
|
|
FaceFeature target = new FaceFeature(info.getData().getFaceFeature());
|
|
FaceFeature target = new FaceFeature(info.getData().getFaceFeature());
|
|
|
FaceFeature source = new FaceFeature(faceCompare.getData());
|
|
FaceFeature source = new FaceFeature(faceCompare.getData());
|
|
|
- Boolean compore = faceService.compore(target, source);
|
|
|
|
|
- logger.info("====compore====" + compore);
|
|
|
|
|
- return ResultData.result(compore, () -> "人脸对比不符!");
|
|
|
|
|
|
|
+ Boolean bool = faceService.compare(target, source);
|
|
|
|
|
+ logger.info("【人脸识别】 识别的用户 userId = {}, 人脸对比结果: {}", faceCompare.getUserId(), bool);
|
|
|
|
|
+ return ResultData.result(bool, () -> "人脸对比不符!");
|
|
|
} else {
|
|
} else {
|
|
|
return ResultData.fail("未获取到对比数据!:" + info.getMsg());
|
|
return ResultData.fail("未获取到对比数据!:" + info.getMsg());
|
|
|
}
|
|
}
|
|
@@ -135,7 +126,7 @@ public class FaceApi {
|
|
|
ImageInfo imageInfo;
|
|
ImageInfo imageInfo;
|
|
|
File file1 = null;
|
|
File file1 = null;
|
|
|
try {
|
|
try {
|
|
|
- file1 = FileUtil.multipartFileToFile(file);
|
|
|
|
|
|
|
+ file1 = FileUtils.multipartFileToFile(file);
|
|
|
imageInfo = faceService.getImageInfo(file1);
|
|
imageInfo = faceService.getImageInfo(file1);
|
|
|
} finally {
|
|
} finally {
|
|
|
if (file1 != null) {
|
|
if (file1 != null) {
|
|
@@ -148,15 +139,13 @@ public class FaceApi {
|
|
|
}
|
|
}
|
|
|
FaceFeature faceFeature = faceService.faceFeature(imageInfo, faceInfos);
|
|
FaceFeature faceFeature = faceService.faceFeature(imageInfo, faceInfos);
|
|
|
if(StringUtils.isNotNull(faceFeature.getFeatureData())){
|
|
if(StringUtils.isNotNull(faceFeature.getFeatureData())){
|
|
|
- logger.info("====人脸比较====");
|
|
|
|
|
R<LabStudentsInfo> info = remoteStudentsService.getInfo(faceCompare.getUserId());
|
|
R<LabStudentsInfo> info = remoteStudentsService.getInfo(faceCompare.getUserId());
|
|
|
if (info.getCode() == 200 && info.getData() != null) {
|
|
if (info.getCode() == 200 && info.getData() != null) {
|
|
|
- logger.info("====人脸data组装====");
|
|
|
|
|
FaceFeature target = new FaceFeature(info.getData().getFaceFeature());
|
|
FaceFeature target = new FaceFeature(info.getData().getFaceFeature());
|
|
|
FaceFeature source = new FaceFeature(faceFeature.getFeatureData());
|
|
FaceFeature source = new FaceFeature(faceFeature.getFeatureData());
|
|
|
- Boolean compore = faceService.compore(target, source);
|
|
|
|
|
- logger.info("====compore====" + compore);
|
|
|
|
|
- return ResultData.result(compore, () -> "人脸对比不符!");
|
|
|
|
|
|
|
+ Boolean bool = faceService.compare(target, source);
|
|
|
|
|
+ logger.info("【人脸识别】 识别的用户 userId = {}, 人脸对比结果: {}", faceCompare.getUserId(), bool);
|
|
|
|
|
+ return ResultData.result(bool, () -> "人脸对比不符!");
|
|
|
} else {
|
|
} else {
|
|
|
return ResultData.fail("未获取到对比数据!:" + info.getMsg());
|
|
return ResultData.fail("未获取到对比数据!:" + info.getMsg());
|
|
|
}
|
|
}
|
|
@@ -165,8 +154,6 @@ public class FaceApi {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 人脸比较
|
|
* 人脸比较
|
|
|
*
|
|
*
|
|
@@ -174,26 +161,31 @@ public class FaceApi {
|
|
|
*/
|
|
*/
|
|
|
@ApiOperation("人脸比较")
|
|
@ApiOperation("人脸比较")
|
|
|
@PostMapping("/multiCompare")
|
|
@PostMapping("/multiCompare")
|
|
|
- public ResultData multiFaceDetection(@RequestBody FaceCompare faceCompare) throws ExecutionException, InterruptedException, TimeoutException {
|
|
|
|
|
- logger.info("====人脸比较====");
|
|
|
|
|
|
|
+ public ResultData multiFaceDetection(@RequestBody FaceCompare faceCompare) throws ExecutionException, InterruptedException {
|
|
|
|
|
+ long time=System.currentTimeMillis();
|
|
|
ResultData<List<LabSysUserInfo>> infoList = remoteStudentsService.getFaceBySecuritySubjectId(faceCompare.getLabId());
|
|
ResultData<List<LabSysUserInfo>> infoList = remoteStudentsService.getFaceBySecuritySubjectId(faceCompare.getLabId());
|
|
|
if(infoList.getCode() == 200 && infoList.getData() != null){
|
|
if(infoList.getCode() == 200 && infoList.getData() != null){
|
|
|
List<Future> list = Optional.ofNullable(infoList.getData()).orElseGet(Collections::emptyList)
|
|
List<Future> list = Optional.ofNullable(infoList.getData()).orElseGet(Collections::emptyList)
|
|
|
.stream()
|
|
.stream()
|
|
|
.map(a->{
|
|
.map(a->{
|
|
|
- Future f = pool.submit((Callable<Object>) () -> {
|
|
|
|
|
- logger.info("执行线程名称:" + Thread.currentThread().getName());
|
|
|
|
|
- return getMultiFaceDetection(a, faceCompare);
|
|
|
|
|
|
|
+ Future f = pool.submit(new Callable<Object>() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Object call() throws Exception {
|
|
|
|
|
+ return getMultiFaceDetection(a,faceCompare);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
return f;
|
|
return f;
|
|
|
})
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
for(Future future:list){
|
|
for(Future future:list){
|
|
|
- ResultData r = (ResultData) future.get();
|
|
|
|
|
|
|
+ ResultData r=(ResultData)future.get();
|
|
|
if(r.getCode()==200){
|
|
if(r.getCode()==200){
|
|
|
|
|
+ long time2=System.currentTimeMillis();
|
|
|
|
|
+ System.out.println("执行时间:"+(time2-time));
|
|
|
return r;
|
|
return r;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ //pool.shutdown();
|
|
|
}
|
|
}
|
|
|
return ResultData.fail("未获取实验室安全准入人脸数据!");
|
|
return ResultData.fail("未获取实验室安全准入人脸数据!");
|
|
|
}
|
|
}
|
|
@@ -202,7 +194,7 @@ public class FaceApi {
|
|
|
Integer isDutyUser=0;
|
|
Integer isDutyUser=0;
|
|
|
FaceFeature target = new FaceFeature(info.getFaceFeature());
|
|
FaceFeature target = new FaceFeature(info.getFaceFeature());
|
|
|
FaceFeature source = new FaceFeature(faceCompare.getData());
|
|
FaceFeature source = new FaceFeature(faceCompare.getData());
|
|
|
- Boolean compore = faceService.compore(target, source);
|
|
|
|
|
|
|
+ Boolean compore = faceService.compare(target, source);
|
|
|
if(compore){
|
|
if(compore){
|
|
|
String userType=info.getUserType();
|
|
String userType=info.getUserType();
|
|
|
Integer isWhite=info.getIsWhite();
|
|
Integer isWhite=info.getIsWhite();
|