Commit ef0950e4 by 姚冰

[chg] 人脸存储,比对修正

1 parent 6f5de97a
...@@ -217,10 +217,13 @@ public class PersonService { ...@@ -217,10 +217,13 @@ public class PersonService {
} }
} }
log.error("matchPerson", e); log.error("matchPerson param1:{}",JSON.toJSONString(requestVo), e);
ResponseVo error = ResponseVo.error(rid, e.getMessage()); ResponseVo error = ResponseVo.error(rid, e.getMessage());
error.setMatch(0); error.setMatch(0);
return error; return error;
} catch (Exception e) {
log.error("matchPerson param:{}", JSON.toJSONString(requestVo), e);
throw e;
} }
} }
...@@ -303,7 +306,7 @@ public class PersonService { ...@@ -303,7 +306,7 @@ public class PersonService {
String fid = faceFeature.getFid(); String fid = faceFeature.getFid();
String unid = faceFeature.getUnid(); String unid = faceFeature.getUnid();
Long gateId = faceFeature.getGateId(); Long gateId = faceFeature.getGateId();
operationList.add(new BulkOperation.Builder().index(new IndexOperation.Builder<PersonInfo>().index(poolId).document(new PersonInfo(unid, personId, feature, null, age, gender, bodyType, personCountTime, fid, personChannelSerialNum, gateId, direction, mallId)).build()).build()); operationList.add(new BulkOperation.Builder().index(new IndexOperation.Builder<PersonInfo>().index(poolId).document(new PersonInfo(unid, personId, null, feature, age, gender, bodyType, personCountTime, fid, personChannelSerialNum, gateId, direction, mallId)).build()).build());
} }
} }
} }
...@@ -521,15 +524,16 @@ public class PersonService { ...@@ -521,15 +524,16 @@ public class PersonService {
KnnQuery.Builder knnQuery = new KnnQuery.Builder(); KnnQuery.Builder knnQuery = new KnnQuery.Builder();
if (null != feature && type == 0) { if (null != feature && type == 0) {
knnQuery.field("data").queryVector(getFeature(feature)).numCandidates(Constant.FACE_MATCH_RESULT_SIZE); knnQuery.field("data").queryVector(getFeature(feature)).numCandidates(Constant.FACE_MATCH_RESULT_SIZE);
queries.add(new Query.Builder().exists(s -> s.field("data").boost(1.0f)).build());
} else if (null != feature && type == 1){ } else if (null != feature && type == 1){
knnQuery.field("body").queryVector(getFeature(feature)).numCandidates(Constant.BODY_MATCH_RESULT_SIZE); knnQuery.field("body").queryVector(getFeature(feature)).numCandidates(Constant.BODY_MATCH_RESULT_SIZE);
queries.add(new Query.Builder().exists(s -> s.field("body").boost(1.0f)).build()); queries.add(new Query.Builder().exists(s -> s.field("body").boost(1.0f)).build());
} }
//根据mallId过滤 //根据mallId过滤
if (person.getMallId() != null) { // if (person.getMallId() != null) {
// boolQuery.filter().add(QueryBuilders.termQuery("mallId", person.getMallId())); //// boolQuery.filter().add(QueryBuilders.termQuery("mallId", person.getMallId()));
queries.add(QueryBuilders.term().field("mallId").value(person.getMallId()).build()._toQuery()); // queries.add(QueryBuilders.term().field("mallId").value(person.getMallId()).build()._toQuery());
} // }
// 根据通道号过滤 // 根据通道号过滤
List<String> channelSerialNums = person.getChannelSerialNums(); List<String> channelSerialNums = person.getChannelSerialNums();
if (CollectionUtils.isNotEmpty(channelSerialNums)) { if (CollectionUtils.isNotEmpty(channelSerialNums)) {
...@@ -568,7 +572,7 @@ public class PersonService { ...@@ -568,7 +572,7 @@ public class PersonService {
private SearchRequest getSearchRequest(String rid, String poolId, Integer matchResultSize, Double[] feature, Person person, int type, Boolean agg) { private SearchRequest getSearchRequest(String rid, String poolId, Integer matchResultSize, Double[] feature, Person person, int type, Boolean agg) {
// BoolQuery.Builder builder = getSearchSourceBuilder(feature, person, type); // BoolQuery.Builder builder = getSearchSourceBuilder(feature, person, type);
Query scriptScoreQuery = getScriptScoreQuery(feature, person, 1); Query scriptScoreQuery = getScriptScoreQuery(feature, person, type);
if (agg) { if (agg) {
// AggregationBuilders.max("max_score", s -> s.field("_score").script(new Script.Builder().source("_score").build())); // AggregationBuilders.max("max_score", s -> s.field("_score").script(new Script.Builder().source("_score").build()));
// Aggregation aggregation = AggregationBuilders.max(s -> s.field("max_score").script(new Script.Builder().source("_score").build())); // Aggregation aggregation = AggregationBuilders.max(s -> s.field("max_score").script(new Script.Builder().source("_score").build()));
...@@ -594,7 +598,13 @@ public class PersonService { ...@@ -594,7 +598,13 @@ public class PersonService {
// log.debug("rid:{} poolId:{} 匹配时参数:{}", rid, poolId, scriptScoreQuery.toString()); // log.debug("rid:{} poolId:{} 匹配时参数:{}", rid, poolId, scriptScoreQuery.toString());
// KnnSearch knnQuery = getKnnSearch(feature, person, type); // KnnSearch knnQuery = getKnnSearch(feature, person, type);
// ScriptScoreQuery scriptScoreQuery = getScriptScoreQuery(feature, person, type); // ScriptScoreQuery scriptScoreQuery = getScriptScoreQuery(feature, person, type);
return new SearchRequest.Builder().index(poolId).query(scriptScoreQuery).source(sourceConfig).size(matchResultSize).minScore(person.getBodyMinScore().doubleValue()/100).build(); double minScore = 0.0;
if (type == 0) {
minScore = person.getFaceMinScore().doubleValue()/100;
} else if (type == 1) {
minScore = person.getBodyMinScore().doubleValue()/100;
}
return new SearchRequest.Builder().index(poolId).query(scriptScoreQuery).source(sourceConfig).size(matchResultSize).minScore(minScore).build();
} }
private List<Person> match0(SearchRequest searchRequest, Boolean agg) throws Exception { private List<Person> match0(SearchRequest searchRequest, Boolean agg) throws Exception {
...@@ -631,7 +641,7 @@ public class PersonService { ...@@ -631,7 +641,7 @@ public class PersonService {
p.setCounttime(Optional.ofNullable((String)hit.getCounttime()) p.setCounttime(Optional.ofNullable((String)hit.getCounttime())
.map(x -> { .map(x -> {
try { try {
return Constant.DATE_FORMAT.get().parse(x); return Constant.DATE_FORMAT.get().parse(x);
} catch (ParseException e) { } catch (ParseException e) {
return null; return null;
} }
...@@ -643,6 +653,7 @@ public class PersonService { ...@@ -643,6 +653,7 @@ public class PersonService {
persons.add(p); persons.add(p);
} }
} }
return persons; return persons;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!