Commit ce7fe5c5 by xmh

修复人体匹配

1 parent 6cf8d7d7
...@@ -32,6 +32,7 @@ public class ResponseVo { ...@@ -32,6 +32,7 @@ public class ResponseVo {
private Integer match; private Integer match;
private List<PoolInfo> poolIds; private List<PoolInfo> poolIds;
private List<Person> matchPersons; private List<Person> matchPersons;
private List<Person> matchBodies;
public ResponseVo(String rid) { public ResponseVo(String rid) {
this.rid = rid; this.rid = rid;
......
...@@ -35,6 +35,7 @@ import javax.annotation.Resource; ...@@ -35,6 +35,7 @@ import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
/** /**
* . * .
...@@ -61,7 +62,8 @@ public class PersonService { ...@@ -61,7 +62,8 @@ public class PersonService {
String poolId = requestVo.getPersonPoolId(); String poolId = requestVo.getPersonPoolId();
List<String> unionPersonPoolId = requestVo.getUnionPersonPoolId(); List<String> unionPersonPoolId = requestVo.getUnionPersonPoolId();
List<String> poolIds = new ArrayList<>(); List<String> poolIds = new ArrayList<>();
List<Person> result = new ArrayList<>(); List<Person> matchFaces = new ArrayList<>();
List<Person> matchBodies = new ArrayList<>();
List<Pool> poolStatus = new ArrayList<>(); List<Pool> poolStatus = new ArrayList<>();
if (unionPersonPoolId != null && unionPersonPoolId.size() > 0) { if (unionPersonPoolId != null && unionPersonPoolId.size() > 0) {
...@@ -77,16 +79,21 @@ public class PersonService { ...@@ -77,16 +79,21 @@ 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> people = matchPerson(id, requestVo.getPerson()); List<Person> face = matchPerson(id, requestVo.getPerson(),0);
result.addAll(people); matchFaces.addAll(face);
List<Person> body = matchPerson(id, requestVo.getPerson(), 1);
matchBodies.addAll(body);
} else { } else {
pool.setStatus(1); pool.setStatus(1);
} }
poolStatus.add(pool); poolStatus.add(pool);
} }
ResponseVo success = ResponseVo.success(rid, "success"); ResponseVo success = ResponseVo.success(rid, "success");
if (result.size() > 0) { if (matchFaces.size() > 0) {
success.setMatchPersons(result); success.setMatchPersons(matchFaces);
}
if (matchBodies.size() > 0) {
success.setMatchBodies(matchBodies);
} }
success.setMatch(1); success.setMatch(1);
success.setPersonPoolStatus(poolStatus); success.setPersonPoolStatus(poolStatus);
...@@ -194,18 +201,22 @@ public class PersonService { ...@@ -194,18 +201,22 @@ public class PersonService {
} }
public List<Person> matchPerson(String poolId, Person person) throws Exception { public List<Person> matchPerson(String poolId, Person person , int type) throws Exception {
List<Person> matchResult = new ArrayList<>(); List<Person> matchResult = new ArrayList<>();
List<FaceFeature> faceFeatures = person.getFaceFeatures(); if (type == 0) {
matchFace(faceFeatures, poolId, matchResult); List<FaceFeature> faceFeatures = person.getFaceFeatures();
matchFace(faceFeatures, poolId, matchResult);
List<BodyFeature> bodyFeatures = person.getBodyFeatures(); }else {
matchBody(bodyFeatures, poolId, matchResult); List<BodyFeature> bodyFeatures = person.getBodyFeatures();
matchBody(bodyFeatures, poolId, matchResult);
}
Stream<Person> stream = matchResult.stream().sorted(Comparator.comparingInt(Person::getScore));
if (matchResult.size() > Constant.MATCH_RESULT_SIZE) { if (matchResult.size() > Constant.MATCH_RESULT_SIZE) {
matchResult = matchResult.stream().sorted(Comparator.comparingInt(Person::getScore)).limit(5).collect(Collectors.toList()); stream = stream.limit(5);
} }
matchResult = stream.collect(Collectors.toList());
return matchResult; return matchResult;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!