|
|
@@ -128,6 +128,9 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
FileInfoEntity fileInfo = uploadFaceFile(base64);
|
|
|
boolean redisFlag = (count != null && count >= 2);
|
|
|
if (ObjectUtils.isEmpty(id) || redisFlag) {
|
|
|
+ if (! imageCenter(base)){
|
|
|
+ return ResultCode.IMAGE_NOT_STANDARD;
|
|
|
+ }
|
|
|
//要做人脸核身
|
|
|
ThirdPartyInterfaceEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
|
|
|
thirdPartyInterfaceEntity.setFileId(fileInfo.getId() + "");
|
|
|
@@ -240,6 +243,9 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
if (flag) {
|
|
|
//说明是客户经理
|
|
|
if (sysUserEntity.getCompareImgId() == null || redisFlag) {
|
|
|
+ if (! imageCenter(base)){
|
|
|
+ return ResultCode.IMAGE_NOT_STANDARD;
|
|
|
+ }
|
|
|
//说明客户经理需要做人脸核身
|
|
|
FileInfoEntity fileInfo = uploadFaceFile(base64);
|
|
|
ThirdPartyInterfaceEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
|
|
|
@@ -261,6 +267,9 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
return ResultCode.LIVE_VIDEO_INVALID;
|
|
|
}
|
|
|
} else if (ObjectUtils.isEmpty(compareImageId) || redisFlag) {
|
|
|
+ if (! imageCenter(base)){
|
|
|
+ return ResultCode.IMAGE_NOT_STANDARD;
|
|
|
+ }
|
|
|
//说明当事人需要做人脸核身
|
|
|
FileInfoEntity fileInfo = uploadFaceFile(base64);
|
|
|
ThirdPartyInterfaceEntity thirdPartyInterfaceEntity = JuheServiceUtil.URLPost(idCard, nickName, base64);
|
|
|
@@ -312,6 +321,80 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 验证照片是否居中
|
|
|
+ * @param base
|
|
|
+ * @param id
|
|
|
+ * @param redisCount
|
|
|
+ * @param count
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean imageCenter(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);
|
|
|
+ //人脸属性检测
|
|
|
+ FunctionConfiguration configuration = new FunctionConfiguration();
|
|
|
+ configuration.setSupportFace3dAngle(true);
|
|
|
+ errorCode = faceEngine.process(imageInfo.getImageData(), imageInfo.getWidth(), imageInfo.getHeight(), imageInfo.getImageFormat(), faceInfoList, configuration);
|
|
|
+ //3D信息检测
|
|
|
+ List<Face3DAngle> face3DAngleList = new ArrayList<Face3DAngle>();
|
|
|
+ errorCode = faceEngine.getFace3DAngle(face3DAngleList);
|
|
|
+ if (CollectionUtils.isEmpty(face3DAngleList)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //俯仰角
|
|
|
+ float pitch = Math.abs(face3DAngleList.get(0).getPitch());
|
|
|
+ //偏向角
|
|
|
+ float yaw = Math.abs(face3DAngleList.get(0).getYaw());
|
|
|
+ log.info("俯仰角:{}", pitch);
|
|
|
+ log.info("偏向角:{}", yaw);
|
|
|
+ if (pitch >= 10 || yaw >= 10) {
|
|
|
+ //照片不符合标准
|
|
|
+ log.info("图片不符合标准");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -444,10 +527,13 @@ public class NotaryDomainImpl implements NotaryDomain {
|
|
|
FaceSimilar faceSimilar = new FaceSimilar();
|
|
|
errorCode = faceEngine.compareFaceFeature(targetFaceFeature, sourceFaceFeature, faceSimilar);
|
|
|
//如果通过 上传文件 修改用户绑定id 如果没通过 返回null证明失败了
|
|
|
+ //引擎卸载
|
|
|
+ errorCode = faceEngine.unInit();
|
|
|
if (faceSimilar.getScore() > 0.8) {
|
|
|
log.info("人脸照片比对通过");
|
|
|
base.delete();
|
|
|
file.delete();
|
|
|
+ redis.del(redisCount);
|
|
|
return ResultCode.SUCCESS;
|
|
|
}
|
|
|
redis.increment(redisCount);
|