Selaa lähdekoodia

照片对比优化

tongfeng 2 vuotta sitten
vanhempi
commit
08536f1faf

+ 15 - 8
eladmin-system/src/main/java/me/zhengjie/base/face/FaceCompareUtil.java

@@ -108,6 +108,7 @@ public class FaceCompareUtil {
         //3D信息检测
         List<Face3DAngle> face3DAngleList = new ArrayList<Face3DAngle>();
         errorCode = faceEngine.getFace3DAngle(face3DAngleList);
+
         if (CollectionUtils.isEmpty(face3DAngleList)) {
             return false;
         }
@@ -137,6 +138,7 @@ public class FaceCompareUtil {
         List<FaceInfo> faceInfoList = new ArrayList<FaceInfo>();
         errorCode = faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);
         System.out.println(faceInfoList);
+
         if (faceInfoList.size()>1){
             return false;
         }
@@ -160,11 +162,7 @@ public class FaceCompareUtil {
         List<FaceInfo> faceInfoList = new ArrayList<FaceInfo>();
         errorCode = faceEngine.detectFaces(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList);
         System.out.println(faceInfoList);
-        //人脸属性检测
-        FunctionConfiguration configuration = new FunctionConfiguration();
-        configuration.setSupportFace3dAngle(true);
-        errorCode = faceEngine.process(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList, configuration);
-        //活体检测
+          //活体检测
         /*List<LivenessInfo> livenessInfoList = new ArrayList<LivenessInfo>();
         errorCode = faceEngine.getLiveness(livenessInfoList);
         if (CollectionUtils.isEmpty(livenessInfoList)){
@@ -230,24 +228,33 @@ public class FaceCompareUtil {
         } catch (FileNotFoundException e) {
             throw new RuntimeException(e);
         }
-        byte[] bytes = new byte[(int) file.length()];
+        byte[] bytes = new byte[(int) base.length()];
         try {
             fileInputStream.read(bytes);
         } catch (IOException e) {
             throw new RuntimeException(e);
+        }finally {
+            try {
+                fileInputStream.close();
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
         }
 
+
+
         String s = Base64.getEncoder().encodeToString(bytes);
 
         FileInfoEntity fileInfo = uploadFaceFile(s);
+
         faceCompareEntity.setFileId(fileInfo.getId()+"");
         faceCompareEntity.setType(0);
         if (score > 0.8) {
             log.info("人脸照片比对通过");
             faceCompareEntity.setResult(1);
             thirdPartyInterfaceRepository.insert(faceCompareEntity);
-            base.delete();
             file.delete();
+            base.delete();
             redis.del(redisCount);
             return ResultCode.SUCCESS;
         }
@@ -256,8 +263,8 @@ public class FaceCompareUtil {
         faceCompareEntity.setMessage("验证失败");
         faceCompareEntity.setResult(0);
         thirdPartyInterfaceRepository.insert(faceCompareEntity);
-        base.delete();
         file.delete();
+        base.delete();
         return ResultCode.LIVE_VIDEO_INVALID;
     }
 

+ 0 - 2
eladmin-system/src/main/java/me/zhengjie/domain/notary/impl/NotaryDomainImpl.java

@@ -230,7 +230,6 @@ public class NotaryDomainImpl implements NotaryDomain {
        File base = null;
         try {
             base = File.createTempFile("compare", ".jpeg");
-            base.deleteOnExit();
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
@@ -327,7 +326,6 @@ public class NotaryDomainImpl implements NotaryDomain {
         /*if (!compareImage(base, id, redisCount, count)) {
             return ResultCode.LIVE_VIDEO_INVALID;
         }*/
-
         ResultCode resultCode = faceCompareUtil.compareImage(base, id, redisCount, faceCompareEntity);
 
         if (resultCode.code()==100){