use of com.amplifyframework.predictions.models.BinaryFeature 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.BinaryFeature in project amplify-android by aws-amplify.
the class RekognitionResultTransformersTest method testFaceDetailConversion.
/**
* Tests that the individual attributes from Rekognition
* face detail are properly converted to a list of binary
* features that are compatible with Amplify's entity
* details.
*/
@Test
public void testFaceDetailConversion() {
FaceDetail faceDetail = new FaceDetail().withBeard(new Beard().withValue(random.nextBoolean()).withConfidence(random.nextFloat())).withSunglasses(new Sunglasses().withValue(random.nextBoolean()).withConfidence(random.nextFloat())).withSmile(new Smile().withValue(random.nextBoolean()).withConfidence(random.nextFloat())).withEyeglasses(new Eyeglasses().withValue(random.nextBoolean()).withConfidence(random.nextFloat())).withMustache(new Mustache().withValue(random.nextBoolean()).withConfidence(random.nextFloat())).withMouthOpen(new MouthOpen().withValue(random.nextBoolean()).withConfidence(random.nextFloat())).withEyesOpen(new EyeOpen().withValue(random.nextBoolean()).withConfidence(random.nextFloat()));
List<BinaryFeature> features = RekognitionResultTransformers.fromFaceDetail(faceDetail);
FeatureAssert.assertMatches(Arrays.asList(faceDetail.getBeard().getValue(), faceDetail.getSunglasses().getValue(), faceDetail.getSmile().getValue(), faceDetail.getEyeglasses().getValue(), faceDetail.getMustache().getValue(), faceDetail.getMouthOpen().getValue(), faceDetail.getEyesOpen().getValue()), features);
}
Aggregations