use of com.amazonaws.services.rekognition.model.SearchFacesByImageRequest in project aws-doc-sdk-examples by awsdocs.
the class SearchFaceMatchingImageCollection method main.
public static void main(String[] args) throws Exception {
AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
ObjectMapper objectMapper = new ObjectMapper();
// Get an image object from S3 bucket.
Image image = new Image().withS3Object(new S3Object().withBucket(bucket).withName(photo));
// Search collection for faces similar to the largest face in the image.
SearchFacesByImageRequest searchFacesByImageRequest = new SearchFacesByImageRequest().withCollectionId(collectionId).withImage(image).withFaceMatchThreshold(70F).withMaxFaces(2);
SearchFacesByImageResult searchFacesByImageResult = rekognitionClient.searchFacesByImage(searchFacesByImageRequest);
System.out.println("Faces matching largest face in image from" + photo);
List<FaceMatch> faceImageMatches = searchFacesByImageResult.getFaceMatches();
for (FaceMatch face : faceImageMatches) {
System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(face));
System.out.println();
}
}
use of com.amazonaws.services.rekognition.model.SearchFacesByImageRequest in project amplify-android by aws-amplify.
the class AWSRekognitionService method detectEntityMatches.
private List<EntityMatch> detectEntityMatches(ByteBuffer imageData, int maxEntities, String collectionId) throws PredictionsException {
SearchFacesByImageRequest request = new SearchFacesByImageRequest().withImage(new Image().withBytes(imageData)).withMaxFaces(maxEntities).withCollectionId(collectionId);
// Detect entities in the given image by matching against a collection of images
final SearchFacesByImageResult result;
try {
result = rekognition.searchFacesByImage(request);
} catch (AmazonClientException serviceException) {
throw new PredictionsException("Amazon Rekognition encountered an error while searching for known faces.", serviceException, "See attached service exception for more details.");
}
List<EntityMatch> matches = new ArrayList<>();
for (FaceMatch rekognitionMatch : result.getFaceMatches()) {
Face face = rekognitionMatch.getFace();
RectF box = RekognitionResultTransformers.fromBoundingBox(face.getBoundingBox());
EntityMatch amplifyMatch = EntityMatch.builder().externalImageId(face.getExternalImageId()).confidence(rekognitionMatch.getSimilarity()).box(box).build();
matches.add(amplifyMatch);
}
return matches;
}
Aggregations