Search in sources :

Example 1 with SearchFacesByImageResult

use of com.amazonaws.services.rekognition.model.SearchFacesByImageResult 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();
    }
}
Also used : SearchFacesByImageRequest(com.amazonaws.services.rekognition.model.SearchFacesByImageRequest) AmazonRekognition(com.amazonaws.services.rekognition.AmazonRekognition) S3Object(com.amazonaws.services.rekognition.model.S3Object) Image(com.amazonaws.services.rekognition.model.Image) SearchFacesByImageResult(com.amazonaws.services.rekognition.model.SearchFacesByImageResult) FaceMatch(com.amazonaws.services.rekognition.model.FaceMatch) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with SearchFacesByImageResult

use of com.amazonaws.services.rekognition.model.SearchFacesByImageResult 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;
}
Also used : RectF(android.graphics.RectF) SearchFacesByImageRequest(com.amazonaws.services.rekognition.model.SearchFacesByImageRequest) AmazonClientException(com.amazonaws.AmazonClientException) ArrayList(java.util.ArrayList) PredictionsException(com.amplifyframework.predictions.PredictionsException) EntityMatch(com.amplifyframework.predictions.models.EntityMatch) Image(com.amazonaws.services.rekognition.model.Image) SearchFacesByImageResult(com.amazonaws.services.rekognition.model.SearchFacesByImageResult) ComparedFace(com.amazonaws.services.rekognition.model.ComparedFace) Face(com.amazonaws.services.rekognition.model.Face) FaceMatch(com.amazonaws.services.rekognition.model.FaceMatch)

Aggregations

FaceMatch (com.amazonaws.services.rekognition.model.FaceMatch)2 Image (com.amazonaws.services.rekognition.model.Image)2 SearchFacesByImageRequest (com.amazonaws.services.rekognition.model.SearchFacesByImageRequest)2 SearchFacesByImageResult (com.amazonaws.services.rekognition.model.SearchFacesByImageResult)2 RectF (android.graphics.RectF)1 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonRekognition (com.amazonaws.services.rekognition.AmazonRekognition)1 ComparedFace (com.amazonaws.services.rekognition.model.ComparedFace)1 Face (com.amazonaws.services.rekognition.model.Face)1 S3Object (com.amazonaws.services.rekognition.model.S3Object)1 PredictionsException (com.amplifyframework.predictions.PredictionsException)1 EntityMatch (com.amplifyframework.predictions.models.EntityMatch)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1