use of software.amazon.awssdk.services.rekognition.model.SearchFacesByImageRequest in project aws-doc-sdk-examples by awsdocs.
the class SearchFaceMatchingImageCollection method searchFaceInCollection.
// snippet-start:[rekognition.java2.search_faces_collection.main]
public static void searchFaceInCollection(RekognitionClient rekClient, String collectionId, String sourceImage) {
try {
InputStream sourceStream = new FileInputStream(new File(sourceImage));
SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream);
Image souImage = Image.builder().bytes(sourceBytes).build();
SearchFacesByImageRequest facesByImageRequest = SearchFacesByImageRequest.builder().image(souImage).maxFaces(10).faceMatchThreshold(70F).collectionId(collectionId).build();
SearchFacesByImageResponse imageResponse = rekClient.searchFacesByImage(facesByImageRequest);
// Display the results.
System.out.println("Faces matching in the collection");
List<FaceMatch> faceImageMatches = imageResponse.faceMatches();
for (FaceMatch face : faceImageMatches) {
System.out.println("The similarity level is " + face.similarity());
System.out.println();
}
} catch (RekognitionException | FileNotFoundException e) {
System.out.println(e.getMessage());
System.exit(1);
}
}
Aggregations