use of com.amplifyframework.predictions.models.LandmarkType in project amplify-android by aws-amplify.
the class RekognitionResultTransformersTest method testLandmarksConversion.
/**
* Tests that the landmarks from Rekognition are converted
* from a list of individual points to a list of Amplify
* landmarks that are mapped by their types.
*/
@Test
public void testLandmarksConversion() {
com.amazonaws.services.rekognition.model.Landmark leftEyeDown = new com.amazonaws.services.rekognition.model.Landmark().withType(com.amazonaws.services.rekognition.model.LandmarkType.LeftEyeDown).withX(random.nextFloat()).withY(random.nextFloat());
com.amazonaws.services.rekognition.model.Landmark leftEyeRight = new com.amazonaws.services.rekognition.model.Landmark().withType(com.amazonaws.services.rekognition.model.LandmarkType.LeftEyeRight).withX(random.nextFloat()).withY(random.nextFloat());
com.amazonaws.services.rekognition.model.Landmark mouthDown = new com.amazonaws.services.rekognition.model.Landmark().withType(com.amazonaws.services.rekognition.model.LandmarkType.MouthDown).withX(random.nextFloat()).withY(random.nextFloat());
List<com.amazonaws.services.rekognition.model.Landmark> rekognitionLandmarks = Arrays.asList(leftEyeDown, leftEyeRight, mouthDown);
List<Landmark> amplifyLandmarks = RekognitionResultTransformers.fromLandmarks(rekognitionLandmarks);
Map<LandmarkType, List<PointF>> map = new HashMap<>();
for (Landmark landmark : amplifyLandmarks) {
map.put(landmark.getType(), landmark.getPoints());
}
assertEquals(map.keySet(), new HashSet<>(Arrays.asList(LandmarkType.ALL_POINTS, LandmarkType.LEFT_EYE, LandmarkType.OUTER_LIPS)));
assertTrue(map.get(LandmarkType.ALL_POINTS).containsAll(Arrays.asList(new PointF(leftEyeDown.getX(), leftEyeDown.getY()), new PointF(leftEyeRight.getX(), leftEyeRight.getY()), new PointF(mouthDown.getX(), mouthDown.getY()))));
assertTrue(map.get(LandmarkType.LEFT_EYE).containsAll(Arrays.asList(new PointF(leftEyeDown.getX(), leftEyeDown.getY()), new PointF(leftEyeRight.getX(), leftEyeRight.getY()))));
assertTrue(map.get(LandmarkType.OUTER_LIPS).contains(new PointF(mouthDown.getX(), mouthDown.getY())));
}
use of com.amplifyframework.predictions.models.LandmarkType in project amplify-android by aws-amplify.
the class RekognitionResultTransformers method fromLandmarks.
/**
* Converts a list of {@link com.amazonaws.services.rekognition.model.Landmark}
* from Amazon Rekognition into Amplify-compatible list of
* {@link Landmark} objects.
* @param landmarks the list of Amazon Rekognition landmark objects
* @return the list of Amplify Predictions landmark objects
*/
@NonNull
public static List<Landmark> fromLandmarks(@Nullable List<com.amazonaws.services.rekognition.model.Landmark> landmarks) {
List<Landmark> amplifyLandmarks = new ArrayList<>();
if (Empty.check(landmarks)) {
return amplifyLandmarks;
}
List<PointF> allPoints = new ArrayList<>();
Map<LandmarkType, List<PointF>> landmarkMap = new HashMap<>();
// Pre-process all of the landmarks into a map of type -> matching points
for (com.amazonaws.services.rekognition.model.Landmark landmark : landmarks) {
LandmarkType type = LandmarkTypeAdapter.fromRekognition(landmark.getType());
PointF point = new PointF(landmark.getX(), landmark.getY());
List<PointF> points = landmarkMap.get(type);
if (points == null) {
points = new ArrayList<>();
landmarkMap.put(type, points);
}
points.add(point);
allPoints.add(point);
}
// Construct Amplify landmarks for each entry in the map + ALL_POINTS
for (Map.Entry<LandmarkType, List<PointF>> entry : landmarkMap.entrySet()) {
Landmark landmark = new Landmark(entry.getKey(), entry.getValue());
amplifyLandmarks.add(landmark);
}
Landmark allPointsLandmark = new Landmark(LandmarkType.ALL_POINTS, allPoints);
amplifyLandmarks.add(allPointsLandmark);
return amplifyLandmarks;
}
Aggregations