|
@@ -59,7 +59,7 @@ public class TencenFaceHandlerImpl implements IFaceHandler {
|
|
|
|
|
|
@Override
|
|
|
public VerifyVO verify(String faceId, byte[] imageBytes) {
|
|
|
- String base64Images= Base64.getEncoder().encodeToString(imageBytes);
|
|
|
+ String base64Images = Base64.getEncoder().encodeToString(imageBytes);
|
|
|
return verify(faceId, base64Images);
|
|
|
}
|
|
|
|
|
@@ -106,7 +106,7 @@ public class TencenFaceHandlerImpl implements IFaceHandler {
|
|
|
req.setImage(imageBase);
|
|
|
// 返回的resp是一个CreatePersonResponse的实例,与请求对象对应
|
|
|
try {
|
|
|
- CreatePersonResponse response= client.CreatePerson(req);
|
|
|
+ CreatePersonResponse response = client.CreatePerson(req);
|
|
|
} catch (TencentCloudSDKException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -115,7 +115,7 @@ public class TencenFaceHandlerImpl implements IFaceHandler {
|
|
|
|
|
|
@Override
|
|
|
public void createPersonByBase(String faceId, String name, byte[] imageBase) {
|
|
|
- String base64Images= Base64.getEncoder().encodeToString(imageBase);
|
|
|
+ String base64Images = Base64.getEncoder().encodeToString(imageBase);
|
|
|
createPersonByBase(faceId, name, base64Images);
|
|
|
}
|
|
|
|
|
@@ -139,7 +139,8 @@ public class TencenFaceHandlerImpl implements IFaceHandler {
|
|
|
// 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
DetectFaceRequest req = new DetectFaceRequest();
|
|
|
req.setMaxFaceNum(1L);
|
|
|
- req.setMinFaceSize(1L);
|
|
|
+ req.setNeedFaceAttributes(1L);
|
|
|
+ req.setNeedQualityDetection(1L);
|
|
|
req.setImage(img);
|
|
|
// 返回的resp是一个DetectFaceResponse的实例,与请求对象对应
|
|
|
DetectFaceResponse resp = null;
|
|
@@ -155,20 +156,40 @@ public class TencenFaceHandlerImpl implements IFaceHandler {
|
|
|
// 输出json格式的字符串回包
|
|
|
log.info(AbstractModel.toJsonString(resp));
|
|
|
FaceInfo[] faceInfos = resp.getFaceInfos();
|
|
|
- if (faceInfos.length>1){
|
|
|
+ if (faceInfos.length > 1) {
|
|
|
throw new AjaxError("存在多个人脸");
|
|
|
}
|
|
|
- FaceInfo faceInfo=faceInfos[0];
|
|
|
- Long score= faceInfo.getFaceQualityInfo().getScore();
|
|
|
- if (score == null || score < 70) {
|
|
|
- throw new AjaxError("请正视摄像头");
|
|
|
+ FaceInfo faceInfo = faceInfos[0];
|
|
|
+ Long score = faceInfo.getFaceQualityInfo().getScore();
|
|
|
+ if (score == null || score < 80) {
|
|
|
+ FaceQualityInfo faceQualityInfo = faceInfo.getFaceQualityInfo();
|
|
|
+ Long brightness = faceQualityInfo.getBrightness();
|
|
|
+ if (brightness == null || brightness < 30) {
|
|
|
+ throw new AjaxError("光线不足");
|
|
|
+ }
|
|
|
+ if (brightness > 70) {
|
|
|
+ throw new AjaxError("光线太亮");
|
|
|
+ }
|
|
|
+ FaceQualityCompleteness completeness = faceQualityInfo.getCompleteness();
|
|
|
+ if (completeness.getMouth() == null || completeness.getMouth() < 50) {
|
|
|
+ throw new AjaxError("请露出嘴巴");
|
|
|
+ }
|
|
|
+ if (completeness.getChin()==null||completeness.getChin()<70) {
|
|
|
+ throw new AjaxError("请露出下巴");
|
|
|
+ }
|
|
|
+ FaceAttributesInfo faceAttributesInfo = faceInfo.getFaceAttributesInfo();
|
|
|
+ if (!faceAttributesInfo.getEyeOpen()) {
|
|
|
+ throw new AjaxError("请睁开眼");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean checkHasPerson(byte[] imageBase) {
|
|
|
- String base64Images= Base64.getEncoder().encodeToString(imageBase);
|
|
|
+ String base64Images = Base64.getEncoder().encodeToString(imageBase);
|
|
|
return checkHasPerson(base64Images);
|
|
|
}
|
|
|
|