|
@@ -17,6 +17,8 @@ import com.iden.common.service.IdenImageStoreService;
|
|
|
|
|
|
import com.iden.common.util.DateUtils;
|
|
import com.iden.common.util.DateUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.apache.logging.log4j.LogManager;
|
|
|
|
+import org.apache.logging.log4j.Logger;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -24,7 +26,7 @@ import javax.annotation.Resource;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
-import java.util.Locale;
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -41,9 +43,10 @@ public class FaceIdenService {
|
|
@Resource
|
|
@Resource
|
|
private IdenCommunityService idenCommunityService;
|
|
private IdenCommunityService idenCommunityService;
|
|
|
|
|
|
- @Value("${data.image.root:#{null}}")
|
|
|
|
- private String imageRoot;
|
|
|
|
|
|
+ @Value("${iden.root:#{null}}")
|
|
|
|
+ private String idenRoot;
|
|
|
|
|
|
|
|
+ private static final Logger logger = LogManager.getLogger(FaceIdenService.class);
|
|
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
@@ -51,21 +54,24 @@ public class FaceIdenService {
|
|
*/
|
|
*/
|
|
|
|
|
|
public void exe() throws Exception {
|
|
public void exe() throws Exception {
|
|
|
|
+ logger.info("FaceIdenService.exe start...");
|
|
|
|
|
|
- File srcImageDirFile = new File(imageRoot + "src/image");
|
|
|
|
|
|
+ File srcImageDirFile = new File(idenRoot + "data/origin/image");
|
|
//初始化引擎
|
|
//初始化引擎
|
|
FaceMonitor faceMonitor = new FaceMonitor();
|
|
FaceMonitor faceMonitor = new FaceMonitor();
|
|
- faceMonitor.init("./model", 0);
|
|
|
|
|
|
+ faceMonitor.init(idenRoot + "face/model", 0);
|
|
|
|
|
|
//使用摄像头编码做目录名,里面图像或视频的名称上加上拍照时间,
|
|
//使用摄像头编码做目录名,里面图像或视频的名称上加上拍照时间,
|
|
- // 比如 2021-12-17_12:30:23.jpg 2021-12-17_12:30:23~2021-12-17_12:33:23.avi
|
|
|
|
|
|
+ // 比如 20211217123023.jpg 20211217123023~20211217123323.mp4
|
|
if (srcImageDirFile.isDirectory()) {
|
|
if (srcImageDirFile.isDirectory()) {
|
|
File[] cameraCodeDirs = srcImageDirFile.listFiles();
|
|
File[] cameraCodeDirs = srcImageDirFile.listFiles();
|
|
if(cameraCodeDirs != null && cameraCodeDirs.length > 0){
|
|
if(cameraCodeDirs != null && cameraCodeDirs.length > 0){
|
|
|
|
+ logger.info("FaceIdenService.exe ...1");
|
|
for(File cameraCodedir : cameraCodeDirs) {
|
|
for(File cameraCodedir : cameraCodeDirs) {
|
|
if(cameraCodedir.isDirectory()){
|
|
if(cameraCodedir.isDirectory()){
|
|
File[] imgFiles = cameraCodedir.listFiles();
|
|
File[] imgFiles = cameraCodedir.listFiles();
|
|
if(imgFiles != null && imgFiles.length > 0){
|
|
if(imgFiles != null && imgFiles.length > 0){
|
|
|
|
+ logger.info("FaceIdenService.exe ...2");
|
|
String cameraCode = cameraCodedir.getName();
|
|
String cameraCode = cameraCodedir.getName();
|
|
QueryWrapper<IdenCamera> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<IdenCamera> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.lambda().eq(IdenCamera::getCode,cameraCode);
|
|
queryWrapper.lambda().eq(IdenCamera::getCode,cameraCode);
|
|
@@ -73,36 +79,42 @@ public class FaceIdenService {
|
|
if(idenCamera == null){
|
|
if(idenCamera == null){
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ logger.info("FaceIdenService.exe ...3");
|
|
//获取特征码
|
|
//获取特征码
|
|
FaceModel[] faceModels = FaceIdenTool.extractFeature(faceMonitor,imgFiles);
|
|
FaceModel[] faceModels = FaceIdenTool.extractFeature(faceMonitor,imgFiles);
|
|
|
|
|
|
List<IdenImageStore> idenImageStoreList = new ArrayList<>();
|
|
List<IdenImageStore> idenImageStoreList = new ArrayList<>();
|
|
- for(File imgFile : imgFiles) {
|
|
|
|
|
|
+ for(int i = 0; i < imgFiles.length; i++) {
|
|
|
|
+ File imgFile = imgFiles[i];
|
|
IdenImageStore idenImageStore = new IdenImageStore();
|
|
IdenImageStore idenImageStore = new IdenImageStore();
|
|
idenImageStore.setCameraId(idenCamera.getId());
|
|
idenImageStore.setCameraId(idenCamera.getId());
|
|
idenImageStore.setCommunityId(idenCamera.getCommunityId());
|
|
idenImageStore.setCommunityId(idenCamera.getCommunityId());
|
|
String photographPlace = idenCamera.getPlace();
|
|
String photographPlace = idenCamera.getPlace();
|
|
|
|
+ logger.info("FaceIdenService.exe ...4");
|
|
if (StringUtils.isEmpty(photographPlace)) {
|
|
if (StringUtils.isEmpty(photographPlace)) {
|
|
IdenCommunity idenCommunity = idenCommunityService.getById(idenCamera.getCommunityId());
|
|
IdenCommunity idenCommunity = idenCommunityService.getById(idenCamera.getCommunityId());
|
|
if(idenCommunity != null) {
|
|
if(idenCommunity != null) {
|
|
photographPlace = idenCommunity.getName() + "(" + idenCamera.getLongitude() + ":" + idenCamera.getLatitude() + ")";
|
|
photographPlace = idenCommunity.getName() + "(" + idenCamera.getLongitude() + ":" + idenCamera.getLatitude() + ")";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ logger.info("FaceIdenService.exe ...5");
|
|
idenImageStore.setPhotographPlace(photographPlace);
|
|
idenImageStore.setPhotographPlace(photographPlace);
|
|
|
|
|
|
String photographTime = imgFile.getName().replace(".jpg","");
|
|
String photographTime = imgFile.getName().replace(".jpg","");
|
|
- idenImageStore.setPhotographTime(DateUtils.strToDate(photographTime,"yyyy-MM-dd_HH:mm:ss"));
|
|
|
|
|
|
+ idenImageStore.setPhotographTime(DateUtils.strToDate(photographTime,"yyyyMMddHHmmss"));
|
|
|
|
|
|
- idenImageStore.setFeatPtr(FaceIdenTool.getFeatPtr(faceModels,imgFile.getName()));
|
|
|
|
|
|
+ idenImageStore.setFeatPtr(FaceIdenTool.getFeatPtr(faceModels,String.valueOf(i)));
|
|
|
|
|
|
- File finalDir = new File(imgFile.getParentFile().getAbsolutePath().replace("src","final"));
|
|
|
|
|
|
+ File finalDir = new File(imgFile.getParentFile().getAbsolutePath().replace("origin","final"));
|
|
if(!finalDir.exists()){
|
|
if(!finalDir.exists()){
|
|
finalDir.mkdirs();
|
|
finalDir.mkdirs();
|
|
}
|
|
}
|
|
|
|
+ logger.info("FaceIdenService.exe ...finalDir == " + finalDir.getAbsolutePath());
|
|
|
|
+ logger.info("FaceIdenService.exe ...imgFile.getName() == " + imgFile.getName());
|
|
|
|
+ File finalImgFile = new File(finalDir, imgFile.getName());
|
|
|
|
+
|
|
|
|
+ logger.info("FaceIdenService.exe ...finalImgFile == " + finalImgFile.getAbsolutePath());
|
|
|
|
|
|
- File finalImgFile = new File(finalDir + imgFile.getName());
|
|
|
|
imgFile.renameTo(finalImgFile);//移动到最终目录
|
|
imgFile.renameTo(finalImgFile);//移动到最终目录
|
|
|
|
|
|
idenImageStore.setImage(finalImgFile.getAbsolutePath());
|
|
idenImageStore.setImage(finalImgFile.getAbsolutePath());
|
|
@@ -111,9 +123,10 @@ public class FaceIdenService {
|
|
|
|
|
|
idenImageStoreList.add(idenImageStore);
|
|
idenImageStoreList.add(idenImageStore);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ logger.info("FaceIdenService.exe ...7");
|
|
//把图像存到图库中
|
|
//把图像存到图库中
|
|
if (CollUtil.isNotEmpty(idenImageStoreList)) {
|
|
if (CollUtil.isNotEmpty(idenImageStoreList)) {
|
|
|
|
+ logger.info("FaceIdenService.exe ...8");
|
|
idenImageStoreService.saveBatch(idenImageStoreList);
|
|
idenImageStoreService.saveBatch(idenImageStoreList);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -122,13 +135,7 @@ public class FaceIdenService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ logger.info("FaceIdenService.exe end");
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- public static void main(String[] args) {
|
|
|
|
- String faceTestDir = "./data/";
|
|
|
|
- String faceFilePath = String.format(Locale.CHINA, "%s%d.jpg", faceTestDir, 1);
|
|
|
|
- System.out.println(faceFilePath);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|