Commit ce426275 by xmh

添加匹配数量

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