Commit ce426275 by xmh

添加匹配数量

1 parent 8ef31fb8
...@@ -42,6 +42,7 @@ public class RequestVo { ...@@ -42,6 +42,7 @@ public class RequestVo {
private Person person; private Person person;
private String personPoolId; private String personPoolId;
private List<String> unionPersonPoolId; private List<String> unionPersonPoolId;
private Integer size;
private FaceFeature newFaceFeature; private FaceFeature newFaceFeature;
......
...@@ -75,6 +75,7 @@ public class PersonService { ...@@ -75,6 +75,7 @@ public class PersonService {
String rid = requestVo.getRid(); String rid = requestVo.getRid();
String poolId = requestVo.getPersonPoolId(); String poolId = requestVo.getPersonPoolId();
List<String> unionPersonPoolId = requestVo.getUnionPersonPoolId(); List<String> unionPersonPoolId = requestVo.getUnionPersonPoolId();
Integer size = requestVo.getSize();
List<String> poolIds = new ArrayList<>(); List<String> poolIds = new ArrayList<>();
List<Person> matchFaces = new ArrayList<>(); List<Person> matchFaces = new ArrayList<>();
List<Person> matchBodies = new ArrayList<>(); List<Person> matchBodies = new ArrayList<>();
...@@ -93,9 +94,9 @@ public class PersonService { ...@@ -93,9 +94,9 @@ public class PersonService {
pool.setPersonPoolId(id); pool.setPersonPoolId(id);
if (poolService.existPool(id)) { if (poolService.existPool(id)) {
pool.setStatus(0); pool.setStatus(0);
List<Person> face = matchPerson(id, requestVo.getPerson(), 0); List<Person> face = matchPerson(id, requestVo.getPerson(), 0, size);
matchFaces.addAll(face); matchFaces.addAll(face);
List<Person> body = matchPerson(id, requestVo.getPerson(), 1); List<Person> body = matchPerson(id, requestVo.getPerson(), 1, size);
matchBodies.addAll(body); matchBodies.addAll(body);
} else { } else {
pool.setStatus(1); pool.setStatus(1);
...@@ -249,16 +250,19 @@ public class PersonService { ...@@ -249,16 +250,19 @@ public class PersonService {
* @return 匹配结果 * @return 匹配结果
* @throws Exception -- * @throws Exception --
*/ */
public List<Person> matchPerson(String poolId, Person person, int type) throws Exception { public List<Person> matchPerson(String poolId, Person person, int type, Integer size) throws Exception {
List<Person> matchResult = new ArrayList<>(); List<Person> matchResult = new ArrayList<>();
int matchResultSize; int matchResultSize;
if (type == 0) { if (type == 0) {
matchFace(poolId, matchResult, person); matchFace(poolId, matchResult, person, size);
matchResultSize = Constant.FACE_MATCH_RESULT_SIZE; matchResultSize = Constant.FACE_MATCH_RESULT_SIZE;
} else { } else {
matchBody(poolId, matchResult, person); matchBody(poolId, matchResult, person, size);
matchResultSize = Constant.BODY_MATCH_RESULT_SIZE; matchResultSize = Constant.BODY_MATCH_RESULT_SIZE;
} }
if (size != null) {
matchResultSize = size;
}
Stream<Person> stream = matchResult.stream().sorted(Comparator.comparingDouble(Person::getScore).reversed()); Stream<Person> stream = matchResult.stream().sorted(Comparator.comparingDouble(Person::getScore).reversed());
if (matchResult.size() > matchResultSize) { if (matchResult.size() > matchResultSize) {
...@@ -268,7 +272,7 @@ public class PersonService { ...@@ -268,7 +272,7 @@ public class PersonService {
return matchResult; return matchResult;
} }
private void matchFace(String poolId, List<Person> matchResult, Person person) throws Exception { private void matchFace(String poolId, List<Person> matchResult, Person person, Integer size) throws Exception {
List<FaceFeature> faceFeatures = person.getFaceFeatures(); List<FaceFeature> faceFeatures = person.getFaceFeatures();
if (faceFeatures != null && faceFeatures.size() > 0) { if (faceFeatures != null && faceFeatures.size() > 0) {
for (FaceFeature faceFeature : faceFeatures) { for (FaceFeature faceFeature : faceFeatures) {
...@@ -278,7 +282,7 @@ public class PersonService { ...@@ -278,7 +282,7 @@ public class PersonService {
continue; continue;
} }
SearchRequest searchRequest = getSearchRequest(poolId, Constant.FACE_MATCH_RESULT_SIZE, feature, person, 0); SearchRequest searchRequest = getSearchRequest(poolId, size == null ? Constant.FACE_MATCH_RESULT_SIZE : size, feature, person, 0);
matchResult.addAll(match0(searchRequest)); matchResult.addAll(match0(searchRequest));
} }
} else { } else {
...@@ -286,7 +290,7 @@ public class PersonService { ...@@ -286,7 +290,7 @@ public class PersonService {
} }
} }
private void matchBody(String poolId, List<Person> matchResult, Person person) throws Exception { private void matchBody(String poolId, List<Person> matchResult, Person person, Integer size) throws Exception {
List<BodyFeature> bodyFeatures = person.getBodyFeatures(); List<BodyFeature> bodyFeatures = person.getBodyFeatures();
if (bodyFeatures != null && bodyFeatures.size() > 0) { if (bodyFeatures != null && bodyFeatures.size() > 0) {
for (BodyFeature faceFeature : bodyFeatures) { for (BodyFeature faceFeature : bodyFeatures) {
...@@ -302,7 +306,7 @@ public class PersonService { ...@@ -302,7 +306,7 @@ public class PersonService {
feature = Arrays.copyOfRange(feature, 3, Constant.BODY_FEATURE_DIMS_2048 + 3); feature = Arrays.copyOfRange(feature, 3, Constant.BODY_FEATURE_DIMS_2048 + 3);
} }
SearchRequest searchRequest = getSearchRequest(poolId, Constant.BODY_MATCH_RESULT_SIZE, feature, person, 1); SearchRequest searchRequest = getSearchRequest(poolId, size == null ? Constant.BODY_MATCH_RESULT_SIZE : size, feature, person, 1);
matchResult.addAll(match0(searchRequest)); matchResult.addAll(match0(searchRequest));
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!