人脸搜索优化
This commit is contained in:
parent
083f67e516
commit
cf3a49d590
@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper;
|
|||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.ycwl.basic.biz.OrderBiz;
|
import com.ycwl.basic.biz.OrderBiz;
|
||||||
import com.ycwl.basic.enums.StatisticEnum;
|
import com.ycwl.basic.enums.StatisticEnum;
|
||||||
|
import com.ycwl.basic.exception.BaseException;
|
||||||
import com.ycwl.basic.facebody.FaceBodyFactory;
|
import com.ycwl.basic.facebody.FaceBodyFactory;
|
||||||
import com.ycwl.basic.facebody.adapter.AliFaceBodyAdapter;
|
import com.ycwl.basic.facebody.adapter.AliFaceBodyAdapter;
|
||||||
import com.ycwl.basic.facebody.adapter.IFaceBodyAdapter;
|
import com.ycwl.basic.facebody.adapter.IFaceBodyAdapter;
|
||||||
@ -229,6 +230,9 @@ public class FaceServiceImpl implements FaceService {
|
|||||||
faceBodyAdapter = FaceBodyFactory.use();
|
faceBodyAdapter = FaceBodyFactory.use();
|
||||||
}
|
}
|
||||||
SearchFaceRespVo scenicDbSearchResult = faceService.searchFace(faceBodyAdapter, String.valueOf(face.getScenicId()), face.getFaceUrl(), "人脸识别");
|
SearchFaceRespVo scenicDbSearchResult = faceService.searchFace(faceBodyAdapter, String.valueOf(face.getScenicId()), face.getFaceUrl(), "人脸识别");
|
||||||
|
if (scenicDbSearchResult == null) {
|
||||||
|
throw new BaseException("人脸识别失败,请换一张试试把~");
|
||||||
|
}
|
||||||
if (scenicDbSearchResult.getSampleListIds() != null && scenicDbSearchResult.getFirstMatchRate() != null && !scenicDbSearchResult.getSampleListIds().isEmpty()) {
|
if (scenicDbSearchResult.getSampleListIds() != null && scenicDbSearchResult.getFirstMatchRate() != null && !scenicDbSearchResult.getSampleListIds().isEmpty()) {
|
||||||
if (scenicConfig != null && scenicConfig.getFaceDetectHelperThreshold() != null && scenicConfig.getFaceDetectHelperThreshold() > 0) {
|
if (scenicConfig != null && scenicConfig.getFaceDetectHelperThreshold() != null && scenicConfig.getFaceDetectHelperThreshold() > 0) {
|
||||||
if (scenicDbSearchResult.getSampleListIds().size() < scenicConfig.getFaceDetectHelperThreshold()) {
|
if (scenicDbSearchResult.getSampleListIds().size() < scenicConfig.getFaceDetectHelperThreshold()) {
|
||||||
|
@ -181,7 +181,7 @@ public class TaskFaceServiceImpl implements TaskFaceService {
|
|||||||
request.setLimit(200);
|
request.setLimit(200);
|
||||||
// request.setQualityScoreThreshold(60f);
|
// request.setQualityScoreThreshold(60f);
|
||||||
FaceDetectLog logEntity = FaceDetectLog.quickCreate(reason, request);
|
FaceDetectLog logEntity = FaceDetectLog.quickCreate(reason, request);
|
||||||
float threshold = 0.525F;
|
float threshold = 0;
|
||||||
int tourMinutes = -1;
|
int tourMinutes = -1;
|
||||||
if (StringUtils.isNumeric(dbName)) {
|
if (StringUtils.isNumeric(dbName)) {
|
||||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(Long.valueOf(dbName));
|
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(Long.valueOf(dbName));
|
||||||
@ -193,9 +193,18 @@ public class TaskFaceServiceImpl implements TaskFaceService {
|
|||||||
tourMinutes = scenicConfig.getTourTime();
|
tourMinutes = scenicConfig.getTourTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (StringUtils.isNumeric(dbName.replace(USER_FACE_DB_NAME, ""))) {
|
||||||
|
Long scenicId = Long.valueOf(dbName.replace(USER_FACE_DB_NAME, ""));
|
||||||
|
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenicId);
|
||||||
|
if (scenicConfig != null) {
|
||||||
|
if (scenicConfig.getFaceScoreThreshold() != null) {
|
||||||
|
threshold = scenicConfig.getFaceScoreThreshold() / 100F;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final float _threshold = threshold;
|
final float _threshold = threshold;
|
||||||
List<Long> acceptFaceSampleIds;
|
List<Long> acceptFaceSampleIds;
|
||||||
|
List<Long> allFaceSampleIds;
|
||||||
try {
|
try {
|
||||||
SearchFaceResp response = adapter.searchFace(dbName, faceUrl);
|
SearchFaceResp response = adapter.searchFace(dbName, faceUrl);
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
@ -219,45 +228,45 @@ public class TaskFaceServiceImpl implements TaskFaceService {
|
|||||||
.filter(StringUtils::isNumeric)
|
.filter(StringUtils::isNumeric)
|
||||||
.map(Long::valueOf)
|
.map(Long::valueOf)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (acceptFaceSampleIds.isEmpty()) {
|
allFaceSampleIds = records.stream()
|
||||||
respVo.setFirstMatchRate(0f);
|
.map(SearchFaceResultItem::getExtData)
|
||||||
respVo.setSampleListIds(Collections.emptyList());
|
.filter(StringUtils::isNumeric)
|
||||||
return respVo;
|
.map(Long::valueOf)
|
||||||
}
|
.collect(Collectors.toList());
|
||||||
List<FaceSampleEntity> faceSampleList = new ArrayList<>();
|
List<FaceSampleEntity> allFaceSampleList = new ArrayList<>();
|
||||||
if (StringUtils.isNumeric(dbName)) { // 景区
|
if (StringUtils.isNumeric(dbName)) { // 景区
|
||||||
faceSampleList = faceSampleMapper.listByIds(acceptFaceSampleIds);
|
allFaceSampleList = faceSampleMapper.listByIds(allFaceSampleIds);
|
||||||
Long firstFaceSampleId = acceptFaceSampleIds.get(0);
|
Long firstFaceSampleId = acceptFaceSampleIds.get(0);
|
||||||
Optional<FaceSampleEntity> firstFaceSample = faceSampleList.stream().filter(faceSample -> faceSample.getId().equals(firstFaceSampleId)).findAny();
|
Optional<FaceSampleEntity> firstFaceSample = allFaceSampleList.stream().filter(faceSample -> faceSample.getId().equals(firstFaceSampleId)).findAny();
|
||||||
if (firstFaceSample.isPresent()) {
|
if (firstFaceSample.isPresent()) {
|
||||||
if (tourMinutes > 0) {
|
if (tourMinutes > 0) {
|
||||||
|
List<FaceSampleEntity> acceptFaceSampleList = faceSampleMapper.listByIds(acceptFaceSampleIds);
|
||||||
Date startDate = DateUtil.offsetMinute(firstFaceSample.get().getCreateAt(), -tourMinutes/2);
|
Date startDate = DateUtil.offsetMinute(firstFaceSample.get().getCreateAt(), -tourMinutes/2);
|
||||||
Date endDate = DateUtil.offsetMinute(firstFaceSample.get().getCreateAt(), tourMinutes/2);
|
Date endDate = DateUtil.offsetMinute(firstFaceSample.get().getCreateAt(), tourMinutes/2);
|
||||||
acceptFaceSampleIds = faceSampleList.stream()
|
acceptFaceSampleIds = acceptFaceSampleList.stream()
|
||||||
.filter(faceSample -> faceSample.getCreateAt().after(startDate) && faceSample.getCreateAt().before(endDate))
|
.filter(faceSample -> faceSample.getCreateAt().after(startDate) && faceSample.getCreateAt().before(endDate))
|
||||||
.map(FaceSampleEntity::getId)
|
.map(FaceSampleEntity::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
log.info("时间范围逻辑:最高匹配:{},时间范围需要在:{}~{}间", firstFaceSample, startDate, endDate);
|
log.info("时间范围逻辑:最高匹配:{},时间范围需要在:{}~{}间", firstFaceSample, startDate, endDate);
|
||||||
} else {
|
} else {
|
||||||
acceptFaceSampleIds = faceSampleList.stream()
|
|
||||||
.map(FaceSampleEntity::getId)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
log.info("时间范围逻辑:景区未限制");
|
log.info("时间范围逻辑:景区未限制");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
acceptFaceSampleIds = faceSampleList.stream()
|
|
||||||
.map(FaceSampleEntity::getId)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
log.info("时间范围逻辑:最高匹配ID:{},未找到", firstFaceSampleId);
|
log.info("时间范围逻辑:最高匹配ID:{},未找到", firstFaceSampleId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (acceptFaceSampleIds.isEmpty()) {
|
||||||
|
respVo.setFirstMatchRate(0f);
|
||||||
|
respVo.setSampleListIds(Collections.emptyList());
|
||||||
|
return respVo;
|
||||||
|
}
|
||||||
List<MatchLocalRecord> collect = new ArrayList<>();
|
List<MatchLocalRecord> collect = new ArrayList<>();
|
||||||
for (SearchFaceResultItem item : records) {
|
for (SearchFaceResultItem item : records) {
|
||||||
MatchLocalRecord record = new MatchLocalRecord();
|
MatchLocalRecord record = new MatchLocalRecord();
|
||||||
record.setIdStr(item.getExtData());
|
record.setIdStr(item.getExtData());
|
||||||
record.setFaceSampleId(Long.parseLong(item.getExtData()));
|
record.setFaceSampleId(Long.parseLong(item.getExtData()));
|
||||||
if (StringUtils.isNumeric(item.getDbName())) {
|
if (StringUtils.isNumeric(item.getDbName())) {
|
||||||
Optional<FaceSampleEntity> optionalFse = faceSampleList.stream().filter(face -> face.getId().equals(Long.parseLong(item.getExtData()))).findAny();
|
Optional<FaceSampleEntity> optionalFse = allFaceSampleList.stream().filter(face -> face.getId().equals(Long.parseLong(item.getExtData()))).findAny();
|
||||||
if (optionalFse.isPresent()) {
|
if (optionalFse.isPresent()) {
|
||||||
DeviceEntity device = deviceRepository.getDevice(optionalFse.get().getDeviceId());
|
DeviceEntity device = deviceRepository.getDevice(optionalFse.get().getDeviceId());
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user