Search in sources :

Example 1 with AgeRange

use of com.amazonaws.services.rekognition.model.AgeRange in project myrobotlab by MyRobotLab.

the class Rekognition method getFaces.

// FIXME make BufferedImage translations...
public List<FaceDetail> getFaces(ByteBuffer imageBytes, Integer width, Integer height) {
    DetectFacesRequest request = new DetectFacesRequest().withImage(new Image().withBytes((imageBytes))).withAttributes(Attribute.ALL);
    DetectFacesResult result = getClient().detectFaces(request);
    System.out.println("Orientation: " + result.getOrientationCorrection() + "\n");
    List<FaceDetail> faceDetails = result.getFaceDetails();
    for (FaceDetail face : faceDetails) {
        System.out.println("Face:");
        ShowBoundingBoxPositions(height, width, face.getBoundingBox(), result.getOrientationCorrection());
        AgeRange ageRange = face.getAgeRange();
        System.out.println("The detected face is estimated to be between " + ageRange.getLow().toString() + " and " + ageRange.getHigh().toString() + " years old.");
        System.out.println();
    }
    return faceDetails;
}
Also used : FaceDetail(com.amazonaws.services.rekognition.model.FaceDetail) AgeRange(com.amazonaws.services.rekognition.model.AgeRange) BufferedImage(java.awt.image.BufferedImage) Image(com.amazonaws.services.rekognition.model.Image) DetectFacesResult(com.amazonaws.services.rekognition.model.DetectFacesResult) DetectFacesRequest(com.amazonaws.services.rekognition.model.DetectFacesRequest)

Example 2 with AgeRange

use of com.amazonaws.services.rekognition.model.AgeRange in project aws-doc-sdk-examples by awsdocs.

the class DetectFaces method main.

public static void main(String[] args) throws Exception {
    // Change bucket to your S3 bucket that contains the image file.
    // Change photo to your image file.
    String photo = "input.jpg";
    String bucket = "bucket";
    AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
    DetectFacesRequest request = new DetectFacesRequest().withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket))).withAttributes(Attribute.ALL);
    try {
        DetectFacesResult result = rekognitionClient.detectFaces(request);
        List<FaceDetail> faceDetails = result.getFaceDetails();
        for (FaceDetail face : faceDetails) {
            if (request.getAttributes().contains("ALL")) {
                AgeRange ageRange = face.getAgeRange();
                System.out.println("The detected face is estimated to be between " + ageRange.getLow().toString() + " and " + ageRange.getHigh().toString() + " years old.");
                System.out.println("Here's the complete set of attributes:");
            } else {
                // non-default attributes have null values.
                System.out.println("Here's the default set of attributes:");
            }
            ObjectMapper objectMapper = new ObjectMapper();
            System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(face));
        }
    } catch (AmazonRekognitionException e) {
        e.printStackTrace();
    }
}
Also used : FaceDetail(com.amazonaws.services.rekognition.model.FaceDetail) AgeRange(com.amazonaws.services.rekognition.model.AgeRange) AmazonRekognitionException(com.amazonaws.services.rekognition.model.AmazonRekognitionException) AmazonRekognition(com.amazonaws.services.rekognition.AmazonRekognition) S3Object(com.amazonaws.services.rekognition.model.S3Object) Image(com.amazonaws.services.rekognition.model.Image) DetectFacesResult(com.amazonaws.services.rekognition.model.DetectFacesResult) DetectFacesRequest(com.amazonaws.services.rekognition.model.DetectFacesRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

AgeRange (com.amazonaws.services.rekognition.model.AgeRange)2 DetectFacesRequest (com.amazonaws.services.rekognition.model.DetectFacesRequest)2 DetectFacesResult (com.amazonaws.services.rekognition.model.DetectFacesResult)2 FaceDetail (com.amazonaws.services.rekognition.model.FaceDetail)2 Image (com.amazonaws.services.rekognition.model.Image)2 AmazonRekognition (com.amazonaws.services.rekognition.AmazonRekognition)1 AmazonRekognitionException (com.amazonaws.services.rekognition.model.AmazonRekognitionException)1 S3Object (com.amazonaws.services.rekognition.model.S3Object)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BufferedImage (java.awt.image.BufferedImage)1