use of com.amplifyframework.predictions.models.AgeRange in project amplify-android by aws-amplify.
the class AWSRekognitionService method detectEntities.
private List<EntityDetails> detectEntities(ByteBuffer imageData) throws PredictionsException {
DetectFacesRequest request = new DetectFacesRequest().withImage(new Image().withBytes(imageData)).withAttributes(Attribute.ALL.toString());
// Detect entities in the given image via Amazon Rekognition
final DetectFacesResult result;
try {
result = rekognition.detectFaces(request);
} catch (AmazonClientException serviceException) {
throw new PredictionsException("Amazon Rekognition encountered an error while detecting faces.", serviceException, "See attached service exception for more details.");
}
List<EntityDetails> entities = new ArrayList<>();
for (FaceDetail face : result.getFaceDetails()) {
// Extract details from face detection
RectF box = RekognitionResultTransformers.fromBoundingBox(face.getBoundingBox());
AgeRange ageRange = RekognitionResultTransformers.fromRekognitionAgeRange(face.getAgeRange());
Pose pose = RekognitionResultTransformers.fromRekognitionPose(face.getPose());
List<Landmark> landmarks = RekognitionResultTransformers.fromLandmarks(face.getLandmarks());
List<BinaryFeature> features = RekognitionResultTransformers.fromFaceDetail(face);
// Gender detection
com.amazonaws.services.rekognition.model.Gender rekognitionGender = face.getGender();
Gender amplifyGender = Gender.builder().value(GenderBinaryTypeAdapter.fromRekognition(rekognitionGender.getValue())).confidence(rekognitionGender.getConfidence()).build();
// Emotion detection
List<Emotion> emotions = new ArrayList<>();
for (com.amazonaws.services.rekognition.model.Emotion rekognitionEmotion : face.getEmotions()) {
EmotionType emotion = EmotionTypeAdapter.fromRekognition(rekognitionEmotion.getType());
Emotion amplifyEmotion = Emotion.builder().value(emotion).confidence(rekognitionEmotion.getConfidence()).build();
emotions.add(amplifyEmotion);
}
Collections.sort(emotions, Collections.reverseOrder());
EntityDetails entity = EntityDetails.builder().box(box).ageRange(ageRange).pose(pose).gender(amplifyGender).landmarks(landmarks).emotions(emotions).features(features).build();
entities.add(entity);
}
return entities;
}
use of com.amplifyframework.predictions.models.AgeRange in project amplify-android by aws-amplify.
the class RekognitionResultTransformersTest method testAgeRangeConversion.
/**
* Tests that the age range from Rekognition is converted
* to an equivalent Amplify age range.
*/
@Test
public void testAgeRangeConversion() {
int low = random.nextInt();
int high = random.nextInt();
// high cannot be lower than low
if (low > high) {
int temp = high;
high = low;
low = temp;
}
com.amazonaws.services.rekognition.model.AgeRange rekognitionAgeRange = new com.amazonaws.services.rekognition.model.AgeRange().withHigh(high).withLow(low);
AgeRange amplifyAgeRange = RekognitionResultTransformers.fromRekognitionAgeRange(rekognitionAgeRange);
assertEquals(rekognitionAgeRange.getHigh().intValue(), amplifyAgeRange.getHigh());
assertEquals(rekognitionAgeRange.getLow().intValue(), amplifyAgeRange.getLow());
}
Aggregations