This commit is contained in:
2025-02-10 20:45:45 +08:00
parent a6157ddad8
commit 958dc05836
8 changed files with 55 additions and 7 deletions

View File

@@ -13,6 +13,8 @@ public interface TaskFaceService {
SearchFaceRespVo searchFace(String dbName, String faceUrl);
SearchFaceRespVo searchFace(String dbName, String faceUrl, String reason);
AddFaceSampleRespVo addFaceSample(Long faceSampleId);
AddFaceSampleRespVo addFaceSample(String dbName, String entityId, String faceUrl, String extData);

View File

@@ -117,7 +117,7 @@ public class TaskFaceServiceImpl implements TaskFaceService {
return vo;
}
Long scenicId = faceRespVO.getScenicId();
SearchFaceRespVo respVo = searchFace(scenicId.toString(), faceRespVO.getFaceUrl());
SearchFaceRespVo respVo = searchFace(scenicId.toString(), faceRespVO.getFaceUrl(), "系统定时任务检索");
if (respVo != null) {
FaceEntity faceEntity = new FaceEntity();
faceEntity.setId(faceId);
@@ -162,11 +162,16 @@ public class TaskFaceServiceImpl implements TaskFaceService {
@Override
public SearchFaceRespVo searchFace(Long scenicId, String faceUrl) {
return searchFace(scenicId.toString(), faceUrl);
return searchFace(scenicId.toString(), faceUrl, "预留字段");
}
@Override
public SearchFaceRespVo searchFace(String dbName, String faceUrl) {
return searchFace(dbName, faceUrl, "预留字段");
}
@Override
public SearchFaceRespVo searchFace(String dbName, String faceUrl, String reason) {
assureFaceDB(dbName);
IAcsClient client = getClient();
SearchFaceRequest request = new SearchFaceRequest();
@@ -174,11 +179,21 @@ public class TaskFaceServiceImpl implements TaskFaceService {
request.setImageUrl(faceUrl);
request.setLimit(100);
// request.setQualityScoreThreshold(60f);
FaceDetectLog log = FaceDetectLog.quickCreate("预留字段", request);
FaceDetectLog log = FaceDetectLog.quickCreate(reason, request);
try {
searchFaceLimiter.acquire();
} catch (InterruptedException ignored) {
}
float threshold = 0.525F;
if (StringUtils.isNumeric(dbName)) {
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(Long.valueOf(dbName));
if (scenicConfig != null) {
if (scenicConfig.getFaceScoreThreshold() != null) {
threshold = scenicConfig.getFaceScoreThreshold() / 100F;
}
}
}
final float _threshold = threshold;
try {
SearchFaceResponse response = client.getAcsResponse(request);
log.fillResponse(response);
@@ -195,7 +210,7 @@ public class TaskFaceServiceImpl implements TaskFaceService {
List<SearchFaceResponse.Data.MatchListItem.FaceItemsItem> records = matchList.get(0).getFaceItems();
log.setMatchRawRecord(records);
List<Long> faceSampleIds = records.stream()
.filter(record -> record.getScore() > 0.525F)
.filter(record -> record.getScore() > _threshold)
.map(SearchFaceResponse.Data.MatchListItem.FaceItemsItem::getExtraData)
.filter(StringUtils::isNumeric)
.map(Long::valueOf)
@@ -205,7 +220,6 @@ public class TaskFaceServiceImpl implements TaskFaceService {
return respVo;
} catch (Exception e) {
log.setMatchRawResult("识别错误,错误为:["+e.getLocalizedMessage()+"]");
e.printStackTrace();
throw new BaseException(e.getMessage());
} finally {
new Thread(() -> {
@@ -221,6 +235,7 @@ public class TaskFaceServiceImpl implements TaskFaceService {
if (device != null) {
record.setDeviceName(device.getName());
}
record.setMatched(item.getScore() > _threshold);
record.setFaceUrl(faceSample.getFaceUrl());
record.setShotDate(faceSample.getCreateAt());
}