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;
}
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);
}
}
Aggregations