Quellcode durchsuchen

新增多人识别判断

tongfeng vor 2 Jahren
Ursprung
Commit
1203e713c3

+ 1 - 1
eladmin-common/src/main/java/me/zhengjie/base/ResultCode.java

@@ -129,7 +129,7 @@ public enum ResultCode {
     DICT_DETAIL_LOCK(40015, "该字典数据被锁定,不允许修改或删除"),
     DEPART_CODE_EXISTED_WITH_ARGS(40016, "组织机构编码【{0}】系统已存在"),
     IMAGE_NOT_STANDARD(40017,"请保持人脸居中"),
-
+    SINGLE_PERSON(40018,"请当事人'单独'认证"),
     /* 数据错误:50001-599999 */
     RESULT_DATA_NONE(50001, "数据未找到"),
     DATA_IS_WRONG(50002, "数据有误"),

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

@@ -119,6 +119,10 @@ public class NotaryDomainImpl implements NotaryDomain {
             return ResultCode.FACEAUTH_FAIL;
         }
 
+        if (imageSingle(base)){
+            return ResultCode.SINGLE_PERSON;
+        }
+
 
         FileInfoEntity fileInfo = uploadFaceFile(base64);
         boolean redisFlag = (count != null && count >= 2);
@@ -235,6 +239,9 @@ public class NotaryDomainImpl implements NotaryDomain {
             log.info("base64转图片异常");
             return ResultCode.FACEAUTH_FAIL;
         }
+        if (imageSingle(base)){
+            return ResultCode.SINGLE_PERSON;
+        }
         boolean redisFlag = (count != null && count >= 2);
         if (flag) {
             //说明是客户经理
@@ -391,6 +398,61 @@ public class NotaryDomainImpl implements NotaryDomain {
     }
 
 
+    /**
+     * 校验图片的当事人是否为一个
+     * @param base
+     * @return
+     */
+    public boolean imageSingle(File base) {
+        //从官网获取
+        FaceEngine faceEngine = new FaceEngine(libpath);
+        //激活引擎
+        int errorCode = faceEngine.activeOnline(appid, sdkkey);
+        if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
+            base.delete();
+            throw new RuntimeException("引擎激活失败");
+        }
+        ActiveFileInfo activeFileInfo = new ActiveFileInfo();
+        errorCode = faceEngine.getActiveFileInfo(activeFileInfo);
+        if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
+            base.delete();
+            throw new RuntimeException("获取激活文件信息失败");
+        }
+        //引擎配置
+        EngineConfiguration engineConfiguration = new EngineConfiguration();
+        engineConfiguration.setDetectMode(DetectMode.ASF_DETECT_MODE_IMAGE);
+        engineConfiguration.setDetectFaceOrientPriority(DetectOrient.ASF_OP_ALL_OUT);
+        engineConfiguration.setDetectFaceMaxNum(10);
+        engineConfiguration.setDetectFaceScaleVal(16);
+        //功能配置
+        FunctionConfiguration functionConfiguration = new FunctionConfiguration();
+        functionConfiguration.setSupportAge(true);
+        functionConfiguration.setSupportFace3dAngle(true);
+        functionConfiguration.setSupportFaceDetect(true);
+        functionConfiguration.setSupportFaceRecognition(true);
+        functionConfiguration.setSupportGender(true);
+        functionConfiguration.setSupportLiveness(true);
+        functionConfiguration.setSupportIRLiveness(true);
+        engineConfiguration.setFunctionConfiguration(functionConfiguration);
+        //初始化引擎
+        errorCode = faceEngine.init(engineConfiguration);
+        if (errorCode != ErrorInfo.MOK.getValue()) {
+            base.delete();
+            throw new RuntimeException("初始化引擎失败");
+        }
+        //人脸检测
+        ImageInfo imageInfo = getRGBData(base);
+        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){
+            System.out.println("请当事人单独认证");
+            return false;
+        }
+        return true;
+    }
+
+
 
     /**
      * 虹软的人脸照片比对