|
@@ -14,7 +14,9 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
@@ -50,7 +52,7 @@ public class TencenFaceHandlerImpl implements IFaceHandler {
|
|
|
* @param baseImg
|
|
|
* @return
|
|
|
*/
|
|
|
- public String faceSearch(String baseImg) {
|
|
|
+ public List<String> faceSearch(String baseImg) {
|
|
|
IaiClient client = this.createClient();
|
|
|
SearchFacesRequest request = new SearchFacesRequest();
|
|
|
request.setImage(baseImg);
|
|
@@ -59,7 +61,7 @@ public class TencenFaceHandlerImpl implements IFaceHandler {
|
|
|
request.setMaxPersonNum(2L);
|
|
|
request.setGroupIds(new String[]{tencenProperties.getGroupId()});
|
|
|
SearchFacesResponse response;
|
|
|
- AtomicReference<String> faceId = new AtomicReference<>("");
|
|
|
+ List<String> faceId = new ArrayList<>();
|
|
|
try {
|
|
|
response = client.SearchFaces(request);
|
|
|
} catch (TencentCloudSDKException e) {
|
|
@@ -67,12 +69,11 @@ public class TencenFaceHandlerImpl implements IFaceHandler {
|
|
|
}
|
|
|
Arrays.stream(response.getResults())
|
|
|
.forEach(result -> {
|
|
|
- Optional<Candidate> optionalCandidate = Arrays.stream(result.getCandidates())
|
|
|
+ Arrays.stream(result.getCandidates())
|
|
|
.filter(candidate -> candidate.getScore() >= 80)
|
|
|
- .findFirst();
|
|
|
- optionalCandidate.ifPresent(candidate -> faceId.set(candidate.getPersonId()));
|
|
|
+ .forEach(candidate -> faceId.add(candidate.getPersonId()));
|
|
|
});
|
|
|
- return faceId.get();
|
|
|
+ return faceId;
|
|
|
}
|
|
|
|
|
|
public void createPersonByBase(String personId, String name, String imageBase) {
|