use of com.amplifyframework.predictions.models.Celebrity in project amplify-android by aws-amplify.
the class AWSRekognitionService method detectCelebrities.
private List<CelebrityDetails> detectCelebrities(ByteBuffer imageData) throws PredictionsException {
RecognizeCelebritiesRequest request = new RecognizeCelebritiesRequest().withImage(new Image().withBytes(imageData));
// Recognize celebrities in the given image via Amazon Rekognition
final RecognizeCelebritiesResult result;
try {
result = rekognition.recognizeCelebrities(request);
} catch (AmazonClientException serviceException) {
throw new PredictionsException("Amazon Rekognition encountered an error while recognizing celebrities.", serviceException, "See attached service exception for more details.");
}
List<CelebrityDetails> celebrities = new ArrayList<>();
for (com.amazonaws.services.rekognition.model.Celebrity rekognitionCelebrity : result.getCelebrityFaces()) {
Celebrity amplifyCelebrity = Celebrity.builder().id(rekognitionCelebrity.getId()).value(rekognitionCelebrity.getName()).confidence(rekognitionCelebrity.getMatchConfidence()).build();
// Get face-specific celebrity details from the result
ComparedFace face = rekognitionCelebrity.getFace();
RectF box = RekognitionResultTransformers.fromBoundingBox(face.getBoundingBox());
Pose pose = RekognitionResultTransformers.fromRekognitionPose(face.getPose());
List<Landmark> landmarks = RekognitionResultTransformers.fromLandmarks(face.getLandmarks());
// Get URL links that are relevant to celebrities
List<URL> urls = new ArrayList<>();
for (String url : rekognitionCelebrity.getUrls()) {
try {
urls.add(new URL(url));
} catch (MalformedURLException badUrl) {
// Ignore bad URL
}
}
CelebrityDetails details = CelebrityDetails.builder().celebrity(amplifyCelebrity).box(box).pose(pose).landmarks(landmarks).urls(urls).build();
celebrities.add(details);
}
return celebrities;
}
Aggregations