Search in sources :

Example 1 with EntityMatch

use of com.amplifyframework.predictions.models.EntityMatch 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)

Example 2 with EntityMatch

use of com.amplifyframework.predictions.models.EntityMatch in project amplify-android by aws-amplify.

the class AWSRekognitionService method detectEntities.

void detectEntities(@NonNull ByteBuffer imageData, @NonNull Consumer<IdentifyResult> onSuccess, @NonNull Consumer<PredictionsException> onError) {
    final IdentifyEntitiesConfiguration config;
    try {
        config = pluginConfiguration.getIdentifyEntitiesConfiguration();
        if (config.isGeneralEntityDetection()) {
            List<EntityDetails> entities = detectEntities(imageData);
            onSuccess.accept(IdentifyEntitiesResult.fromEntityDetails(entities));
        } else {
            int maxEntities = config.getMaxEntities();
            String collectionId = config.getCollectionId();
            List<EntityMatch> matches = detectEntityMatches(imageData, maxEntities, collectionId);
            onSuccess.accept(IdentifyEntityMatchesResult.fromEntityMatches(matches));
        }
    } catch (PredictionsException exception) {
        onError.accept(exception);
    }
}
Also used : IdentifyEntitiesConfiguration(com.amplifyframework.predictions.aws.configuration.IdentifyEntitiesConfiguration) EntityDetails(com.amplifyframework.predictions.models.EntityDetails) EntityMatch(com.amplifyframework.predictions.models.EntityMatch) PredictionsException(com.amplifyframework.predictions.PredictionsException)

Aggregations

PredictionsException (com.amplifyframework.predictions.PredictionsException)2 EntityMatch (com.amplifyframework.predictions.models.EntityMatch)2 RectF (android.graphics.RectF)1 AmazonClientException (com.amazonaws.AmazonClientException)1 ComparedFace (com.amazonaws.services.rekognition.model.ComparedFace)1 Face (com.amazonaws.services.rekognition.model.Face)1 FaceMatch (com.amazonaws.services.rekognition.model.FaceMatch)1 Image (com.amazonaws.services.rekognition.model.Image)1 SearchFacesByImageRequest (com.amazonaws.services.rekognition.model.SearchFacesByImageRequest)1 SearchFacesByImageResult (com.amazonaws.services.rekognition.model.SearchFacesByImageResult)1 IdentifyEntitiesConfiguration (com.amplifyframework.predictions.aws.configuration.IdentifyEntitiesConfiguration)1 EntityDetails (com.amplifyframework.predictions.models.EntityDetails)1 ArrayList (java.util.ArrayList)1