|
@@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.face.monitor.FaceMonitor;
|
|
import com.face.monitor.FaceMonitor;
|
|
import com.face.monitor.model.FaceModel;
|
|
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.RedisUtil;
|
|
import com.iden.common.entity.IdenCamera;
|
|
import com.iden.common.entity.IdenCamera;
|
|
import com.iden.common.entity.IdenCommunity;
|
|
import com.iden.common.entity.IdenCommunity;
|
|
import com.iden.common.entity.IdenFaceImage;
|
|
import com.iden.common.entity.IdenFaceImage;
|
|
@@ -50,6 +52,8 @@ public class FaceIdenService {
|
|
@Resource
|
|
@Resource
|
|
private PersonService personService;
|
|
private PersonService personService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private RedisUtil redisUtil;
|
|
|
|
|
|
@Value("${iden.root:#{null}}")
|
|
@Value("${iden.root:#{null}}")
|
|
private String idenRoot;
|
|
private String idenRoot;
|
|
@@ -59,7 +63,7 @@ public class FaceIdenService {
|
|
private static final Logger logger = LogManager.getLogger(FaceIdenService.class);
|
|
private static final Logger logger = LogManager.getLogger(FaceIdenService.class);
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 处理各摄像头上传的图像,去除模糊的、没有人脸的、连拍的图像
|
|
|
|
|
|
+ * 处理各摄像头上传的图像,去除没有人脸的、不是正面的、不符合标准的、连拍的图像
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
public void handleCameraImage() throws Exception {
|
|
public void handleCameraImage() throws Exception {
|
|
@@ -96,7 +100,27 @@ public class FaceIdenService {
|
|
List<IdenFaceImage> idenFaceImageList = new ArrayList<>();
|
|
List<IdenFaceImage> idenFaceImageList = new ArrayList<>();
|
|
for(int i = 0; i < imgFiles.length; i++) {
|
|
for(int i = 0; i < imgFiles.length; i++) {
|
|
File imgFile = imgFiles[i];
|
|
File imgFile = imgFiles[i];
|
|
|
|
+ String imgFileName = imgFile.getName();
|
|
IdenFaceImage idenFaceImage = new IdenFaceImage();
|
|
IdenFaceImage idenFaceImage = new IdenFaceImage();
|
|
|
|
+ //识别特征码
|
|
|
|
+ if (faceModels[i] != null) {
|
|
|
|
+ String featPtr = ByteUtil.byte2Hex(faceModels[i].getFeatValue());
|
|
|
|
+ //没有人脸的、不是正面的、不符合标准的,连拍的图片
|
|
|
|
+ if(isBad(featPtr) || isContinuation(cameraCode,imgFileName,featPtr)) {
|
|
|
|
+ File discardDir = new File(imgFile.getParentFile().getAbsolutePath().replace("origin","discardDir"));
|
|
|
|
+ if(!discardDir.exists()){
|
|
|
|
+ discardDir.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ File finalImgFile = new File(discardDir, imgFileName);
|
|
|
|
+ imgFile.renameTo(finalImgFile);//移动到废弃目录
|
|
|
|
+ continue;
|
|
|
|
+ } else {
|
|
|
|
+ idenFaceImage.setFeatPtr(featPtr);
|
|
|
|
+ //存到redis
|
|
|
|
+ redisUtil.hset(RedisKeyConstant.HANDLE_CAMERA_IMAGE_FIRST + "_" + cameraCode, imgFileName, featPtr, RedisKeyConstant.HANDLE_CAMERA_IMAGE_FIRST_TIME);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
idenFaceImage.setCameraId(idenCamera.getId());
|
|
idenFaceImage.setCameraId(idenCamera.getId());
|
|
idenFaceImage.setCommunityId(idenCamera.getCommunityId());
|
|
idenFaceImage.setCommunityId(idenCamera.getCommunityId());
|
|
String photographPlace = idenCamera.getPlace();
|
|
String photographPlace = idenCamera.getPlace();
|
|
@@ -109,15 +133,10 @@ public class FaceIdenService {
|
|
idenFaceImage.setPhotographPlace(photographPlace);
|
|
idenFaceImage.setPhotographPlace(photographPlace);
|
|
idenFaceImage.setLongitude(idenCamera.getLongitude());
|
|
idenFaceImage.setLongitude(idenCamera.getLongitude());
|
|
idenFaceImage.setLatitude(idenCamera.getLatitude());
|
|
idenFaceImage.setLatitude(idenCamera.getLatitude());
|
|
- String imgFileName = imgFile.getName();
|
|
|
|
|
|
+
|
|
String photographTime = imgFileName.substring(0, imgFileName.indexOf("_"));
|
|
String photographTime = imgFileName.substring(0, imgFileName.indexOf("_"));
|
|
idenFaceImage.setPhotographTime(DateUtils.strToDate(photographTime,"yyyyMMddHHmmss"));
|
|
idenFaceImage.setPhotographTime(DateUtils.strToDate(photographTime,"yyyyMMddHHmmss"));
|
|
|
|
|
|
- //识别特征码
|
|
|
|
- if(faceModels[i] != null){
|
|
|
|
- idenFaceImage.setFeatPtr(ByteUtil.byte2Hex(faceModels[i].getFeatValue()));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
File finalDir = new File(imgFile.getParentFile().getAbsolutePath().replace("origin","final"));
|
|
File finalDir = new File(imgFile.getParentFile().getAbsolutePath().replace("origin","final"));
|
|
if(!finalDir.exists()){
|
|
if(!finalDir.exists()){
|
|
finalDir.mkdirs();
|
|
finalDir.mkdirs();
|
|
@@ -175,6 +194,48 @@ public class FaceIdenService {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ private boolean isBad(String featPtr){
|
|
|
|
+ if (StringUtils.isEmpty(featPtr)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ char[] chars = featPtr.toCharArray();
|
|
|
|
+
|
|
|
|
+ for (char c : chars){
|
|
|
|
+ if(!String.valueOf(c).equals("0")){
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean isContinuation(String cameraCode,String imgFileName, String featPtr) {
|
|
|
|
+ String photographTime = imgFileName.substring(0, imgFileName.indexOf("_"));
|
|
|
|
+ Long photographTimeLong = DateUtils.strToDate(photographTime,"yyyyMMddHHmmss").getTime();
|
|
|
|
+ //获取cameraCode/final下图片
|
|
|
|
+ File originImageDirFile = new File(idenRoot + "data/final/camera/image");
|
|
|
|
+ File[] imgFiles = originImageDirFile.listFiles();
|
|
|
|
+ List<String> featPtrList = new ArrayList<>();
|
|
|
|
+ if (imgFiles != null && imgFiles.length > 0) {
|
|
|
|
+ for(File imgFile : imgFiles) {
|
|
|
|
+ String photographTimeTmp = imgFileName.substring(0, imgFile.getName().indexOf("_"));
|
|
|
|
+ Long photographTimeTmpLong = DateUtils.strToDate(photographTimeTmp,"yyyyMMddHHmmss").getTime();
|
|
|
|
+
|
|
|
|
+ //目标图片和以前图片拍照时间相差2分钟内
|
|
|
|
+ if (photographTimeLong <= photographTimeTmpLong + 2 * 60 * 1000) {
|
|
|
|
+ String featPtrTmp = (String)redisUtil.hget(RedisKeyConstant.HANDLE_CAMERA_IMAGE_FIRST + "_" + cameraCode, imgFile.getName());
|
|
|
|
+ featPtrList.add(featPtrTmp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return FaceIdenTool.isHit(idenRoot,featPtr,featPtrList);
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
* @throws Exception
|
|
* @throws Exception
|