Kaynağa Gözat

导入带图像

suntianwu 3 yıl önce
ebeveyn
işleme
80ce47cc13

+ 36 - 12
src/main/java/com/iden/bms/service/PersonService.java

@@ -25,6 +25,7 @@ import com.iden.common.service.IdenPersonCrowdRefService;
 import com.iden.common.service.IdenPersonService;
 import com.iden.common.util.DateUtils;
 import com.iden.common.util.ImgUtil;
+import com.iden.common.util.StringUtil;
 import com.iden.common.vo.*;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.logging.log4j.LogManager;
@@ -471,6 +472,16 @@ public class PersonService {
                         personVO.setImage(fileUrl + "person/image/" + idenCommunity.getCode() +"/" + saveFileName);
                     }
 
+                    String image = personVO.getImage();
+                    if(StringUtils.isNotEmpty(image)) {
+                        String featPtr = idenFeatPtr(image,idenCommunity.getCode());
+                        if(StringUtils.isNotEmpty(featPtr)) {
+                            personVO.setFeatPtr(featPtr);
+                        } else {
+                            throw new BDException("图像识别失败,请上传正确人脸图像");
+                        }
+                    }
+
                     personVOList.add(personVO);
 
                 }
@@ -480,6 +491,9 @@ public class PersonService {
                     personVOList.forEach(item->{
                         IdenPerson idenPerson = new IdenPerson();
                         BeanUtil.copyProperties(item,idenPerson);
+                        idenPerson.setUid(UUID.randomUUID().toString());
+
+                        idenPerson.setCreateTime(new Date());
                         idenPersonService.save(idenPerson);
 
                         personIdList.add(idenPerson.getId());
@@ -630,20 +644,13 @@ public class PersonService {
         idenPerson.setCreateTime(new Date());
         //识别
         String image = idenPerson.getImage();
-        if(StringUtils.isNotEmpty(image)){
-            String fileName = image.substring(image.lastIndexOf("/"));
-            File imgFile = new File(idenRoot + "data/final/person/image/"+ idenCommunity.getCode() + "/"  + fileName);
-            String featPtr = FaceIdenTool.getFeatPtr(idenRoot,imgFile);
-            if (FaceIdenTool.isBad(featPtr)) {
-                File discardDir = new File(imgFile.getParentFile().getAbsolutePath().replace("final","discard"));
-                if(!discardDir.exists()){
-                    discardDir.mkdirs();
-                }
-                File discardImgFile = new File(discardDir, fileName);
-                imgFile.renameTo(discardImgFile);//移动到废弃目录
+        if(StringUtils.isNotEmpty(image)) {
+            String featPtr = idenFeatPtr(image,idenCommunity.getCode());
+            if(StringUtils.isNotEmpty(featPtr)) {
+                idenPerson.setFeatPtr(featPtr);
+            } else {
                 throw new BDException("图像识别失败,请上传正确人脸图像");
             }
-            idenPerson.setFeatPtr(featPtr);
         }
 
         this.idenPersonService.save(idenPerson);
@@ -700,6 +707,23 @@ public class PersonService {
         this.idenPersonService.updateById(idenPerson);
     }
 
+    private String idenFeatPtr(String image,String communityCode) {
+
+        String fileName = image.substring(image.lastIndexOf("/"));
+        File imgFile = new File(idenRoot + "data/final/person/image/"+ communityCode + "/"  + fileName);
+        String featPtr = FaceIdenTool.getFeatPtr(idenRoot,imgFile);
+        if (FaceIdenTool.isBad(featPtr)) {
+            File discardDir = new File(imgFile.getParentFile().getAbsolutePath().replace("final","discard"));
+            if(!discardDir.exists()){
+                discardDir.mkdirs();
+            }
+            File discardImgFile = new File(discardDir, fileName);
+            imgFile.renameTo(discardImgFile);//移动到废弃目录
+            featPtr = null;
+        }
+       return featPtr;
+
+    }
     /**
      * 根据图像文件名称得到IdenPerson
      * @param imageFileName