|
@@ -10,20 +10,19 @@ import com.face.monitor.model.FaceModel;
|
|
import com.iden.bms.service.PersonService;
|
|
import com.iden.bms.service.PersonService;
|
|
import com.iden.common.cache.RedisKeyConstant;
|
|
import com.iden.common.cache.RedisKeyConstant;
|
|
import com.iden.common.cache.RedisUtil;
|
|
import com.iden.common.cache.RedisUtil;
|
|
-import com.iden.common.entity.IdenCamera;
|
|
|
|
-import com.iden.common.entity.IdenCommunity;
|
|
|
|
-import com.iden.common.entity.IdenFaceImage;
|
|
|
|
|
|
+import com.iden.common.entity.*;
|
|
|
|
|
|
-import com.iden.common.entity.IdenPerson;
|
|
|
|
import com.iden.common.enums.HandleWarningStatusEnum;
|
|
import com.iden.common.enums.HandleWarningStatusEnum;
|
|
import com.iden.common.enums.PersonTypeEnum;
|
|
import com.iden.common.enums.PersonTypeEnum;
|
|
import com.iden.common.service.IdenCameraService;
|
|
import com.iden.common.service.IdenCameraService;
|
|
|
|
+import com.iden.common.service.IdenCameraVideoService;
|
|
import com.iden.common.service.IdenCommunityService;
|
|
import com.iden.common.service.IdenCommunityService;
|
|
import com.iden.common.service.IdenFaceImageService;
|
|
import com.iden.common.service.IdenFaceImageService;
|
|
|
|
|
|
import com.iden.common.util.ByteUtil;
|
|
import com.iden.common.util.ByteUtil;
|
|
import com.iden.common.util.DateUtils;
|
|
import com.iden.common.util.DateUtils;
|
|
import com.iden.common.util.FileUtil;
|
|
import com.iden.common.util.FileUtil;
|
|
|
|
+import com.iden.common.util.VideoUtil;
|
|
import com.iden.common.vo.FaceRetrieveResultVO;
|
|
import com.iden.common.vo.FaceRetrieveResultVO;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.LogManager;
|
|
@@ -52,14 +51,16 @@ public class FaceIdenService {
|
|
private IdenCommunityService idenCommunityService;
|
|
private IdenCommunityService idenCommunityService;
|
|
@Resource
|
|
@Resource
|
|
private PersonService personService;
|
|
private PersonService personService;
|
|
|
|
+ @Resource
|
|
|
|
+ private IdenCameraVideoService idenCameraVideoService;
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private RedisUtil redisUtil;
|
|
private RedisUtil redisUtil;
|
|
|
|
|
|
@Value("${iden.root:#{null}}")
|
|
@Value("${iden.root:#{null}}")
|
|
private String idenRoot;
|
|
private String idenRoot;
|
|
- @Value("${image.url:#{null}}")
|
|
|
|
- private String imageUrl;
|
|
|
|
|
|
+ @Value("${file.url:#{null}}")
|
|
|
|
+ private String fileUrl;
|
|
|
|
|
|
private static final Logger logger = LogManager.getLogger(FaceIdenService.class);
|
|
private static final Logger logger = LogManager.getLogger(FaceIdenService.class);
|
|
|
|
|
|
@@ -72,8 +73,8 @@ public class FaceIdenService {
|
|
|
|
|
|
File originImageDirFile = new File(idenRoot + "data/origin/camera/image");
|
|
File originImageDirFile = new File(idenRoot + "data/origin/camera/image");
|
|
|
|
|
|
- //使用摄像头编码做目录名,里面图像或视频的名称上加上拍照时间,
|
|
|
|
- // 比如 20211217123023.jpg 20211217123023~20211217123323.mp4
|
|
|
|
|
|
+ //使用摄像头编码做目录名,里面图像的名称上加上拍照时间,
|
|
|
|
+ // 比如 20211222123223_76639ced-6409-11ec-b8f9-fa163e4e1e9f.jpg
|
|
if (originImageDirFile.isDirectory()) {
|
|
if (originImageDirFile.isDirectory()) {
|
|
File[] cameraCodeDirs = originImageDirFile.listFiles();
|
|
File[] cameraCodeDirs = originImageDirFile.listFiles();
|
|
if(cameraCodeDirs != null && cameraCodeDirs.length > 0){
|
|
if(cameraCodeDirs != null && cameraCodeDirs.length > 0){
|
|
@@ -81,6 +82,7 @@ public class FaceIdenService {
|
|
//初始化引擎,加载人员图像人脸特征库
|
|
//初始化引擎,加载人员图像人脸特征库
|
|
String personImageDir = idenRoot + "data/final/person";
|
|
String personImageDir = idenRoot + "data/final/person";
|
|
|
|
|
|
|
|
+ //递归获取人员图像目录下的图像文件
|
|
List<File> imgPersonFileList = new ArrayList<>();
|
|
List<File> imgPersonFileList = new ArrayList<>();
|
|
imgPersonFileList = FileUtil.getFiles(new File(personImageDir),imgPersonFileList);
|
|
imgPersonFileList = FileUtil.getFiles(new File(personImageDir),imgPersonFileList);
|
|
File[] imgPersonFiles = new File[imgPersonFileList.size()];
|
|
File[] imgPersonFiles = new File[imgPersonFileList.size()];
|
|
@@ -158,7 +160,7 @@ public class FaceIdenService {
|
|
|
|
|
|
imgFile.renameTo(finalImgFile);//移动到最终目录
|
|
imgFile.renameTo(finalImgFile);//移动到最终目录
|
|
|
|
|
|
- idenFaceImage.setImage( imageUrl + cameraCode + "/" + finalImgFile.getName());
|
|
|
|
|
|
+ idenFaceImage.setImage( fileUrl + "camera/image/" + cameraCode + "/" + finalImgFile.getName());
|
|
|
|
|
|
//和人员图像库比对特征码,关联personId
|
|
//和人员图像库比对特征码,关联personId
|
|
if(faceModels[i] != null){
|
|
if(faceModels[i] != null){
|
|
@@ -263,17 +265,64 @@ public class FaceIdenService {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* 把摄像头上传的图像解开为一帧帧图片,放到图像目录下,等待识别引擎处理
|
|
* 把摄像头上传的图像解开为一帧帧图片,放到图像目录下,等待识别引擎处理
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
-
|
|
|
|
public void handleCameraVideo() throws Exception {
|
|
public void handleCameraVideo() throws Exception {
|
|
|
|
+ logger.info("FaceIdenService.handleCameraVideo start...");
|
|
|
|
+ File originVideoDirFile = new File(idenRoot + "data/origin/camera/video");
|
|
|
|
+ //使用摄像头编码做目录名,里面存放视频,名称里包含拍摄结束时间
|
|
|
|
+ // 比如 20211217123343_76639ced-6409-11ec-b8f9-fa883e4e1e9f.mp4
|
|
|
|
+ if (originVideoDirFile.isDirectory()) {
|
|
|
|
+ File[] cameraCodeDirs = originVideoDirFile.listFiles();
|
|
|
|
+ if (cameraCodeDirs != null && cameraCodeDirs.length > 0) {
|
|
|
|
+ for(File cameraCodedir : cameraCodeDirs) {
|
|
|
|
+ if (cameraCodedir.isDirectory()) {
|
|
|
|
+ File[] videoFiles = FileUtil.sortByName(cameraCodedir.listFiles());
|
|
|
|
+ if (videoFiles != null && videoFiles.length > 0) {
|
|
|
|
+ String cameraCode = cameraCodedir.getName();
|
|
|
|
+ QueryWrapper<IdenCamera> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.lambda().eq(IdenCamera::getCode,cameraCode);
|
|
|
|
+ IdenCamera idenCamera = idenCameraService.getOne(queryWrapper);
|
|
|
|
+ if(idenCamera == null){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ for(File videoFile : videoFiles){
|
|
|
|
+ String videoFileName = videoFile.getName();
|
|
|
|
+ String shootEndTimeStr = videoFileName.substring(0, videoFileName.indexOf("_"));
|
|
|
|
+ Date shootEndTime = DateUtils.strToDate(shootEndTimeStr,"yyyyMMddHHmmss");
|
|
|
|
+ VideoUtil.fetchAllPic(videoFile,idenRoot + "data/origin/camera/image/" + cameraCode, shootEndTime);
|
|
|
|
+
|
|
|
|
+ File finalDir = new File(videoFile.getParentFile().getAbsolutePath().replace("origin","final"));
|
|
|
|
+ if(!finalDir.exists()){
|
|
|
|
+ finalDir.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ logger.info("FaceIdenService.handleCameraVideo ...finalDir == " + finalDir.getAbsolutePath());
|
|
|
|
+ logger.info("FaceIdenService.handleCameraVideo ...videoFile.getName() == " + videoFileName);
|
|
|
|
+ File finalvideoFile = new File(finalDir, videoFileName);
|
|
|
|
+
|
|
|
|
+ logger.info("FaceIdenService.handleCameraVideo ...finalvideoFile == " + finalvideoFile.getAbsolutePath());
|
|
|
|
+ videoFile.renameTo(finalvideoFile);//移动到最终目录
|
|
|
|
+
|
|
|
|
+ IdenCameraVideo idenCameraVideo = new IdenCameraVideo();
|
|
|
|
+ idenCameraVideo.setVideoUrl(fileUrl + "camera/video/" + cameraCode + "/" + videoFileName);
|
|
|
|
+ idenCameraVideo.setCameraId(idenCamera.getId());
|
|
|
|
+ idenCameraVideo.setCommunityId(idenCamera.getCommunityId());
|
|
|
|
+ idenCameraVideo.setName(videoFileName.substring(0,videoFileName.lastIndexOf(".mp4")));
|
|
|
|
+ idenCameraVideo.setPhotographTime(shootEndTime);
|
|
|
|
+ idenCameraVideo.setCreateTime(new Date());
|
|
|
|
+ idenCameraVideoService.save(idenCameraVideo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ logger.info("FaceIdenService.handleCameraImage end");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|