Search in sources :

Example 1 with AgeRange

use of software.amazon.awssdk.services.rekognition.model.AgeRange in project aws-doc-sdk-examples by awsdocs.

the class DetectFaces method detectFacesinImage.

// snippet-start:[rekognition.java2.detect_faces.main]
public static void detectFacesinImage(RekognitionClient rekClient, String sourceImage) {
    try {
        InputStream sourceStream = new FileInputStream(new File(sourceImage));
        SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream);
        // Create an Image object for the source image.
        Image souImage = Image.builder().bytes(sourceBytes).build();
        DetectFacesRequest facesRequest = DetectFacesRequest.builder().attributes(Attribute.ALL).image(souImage).build();
        DetectFacesResponse facesResponse = rekClient.detectFaces(facesRequest);
        List<FaceDetail> faceDetails = facesResponse.faceDetails();
        for (FaceDetail face : faceDetails) {
            AgeRange ageRange = face.ageRange();
            System.out.println("The detected face is estimated to be between " + ageRange.low().toString() + " and " + ageRange.high().toString() + " years old.");
            System.out.println("There is a smile : " + face.smile().value().toString());
        }
    } catch (RekognitionException | FileNotFoundException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) AgeRange(software.amazon.awssdk.services.rekognition.model.AgeRange) FileNotFoundException(java.io.FileNotFoundException) Image(software.amazon.awssdk.services.rekognition.model.Image) FileInputStream(java.io.FileInputStream) SdkBytes(software.amazon.awssdk.core.SdkBytes) FaceDetail(software.amazon.awssdk.services.rekognition.model.FaceDetail) DetectFacesResponse(software.amazon.awssdk.services.rekognition.model.DetectFacesResponse) File(java.io.File) DetectFacesRequest(software.amazon.awssdk.services.rekognition.model.DetectFacesRequest)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 SdkBytes (software.amazon.awssdk.core.SdkBytes)1 AgeRange (software.amazon.awssdk.services.rekognition.model.AgeRange)1 DetectFacesRequest (software.amazon.awssdk.services.rekognition.model.DetectFacesRequest)1 DetectFacesResponse (software.amazon.awssdk.services.rekognition.model.DetectFacesResponse)1 FaceDetail (software.amazon.awssdk.services.rekognition.model.FaceDetail)1 Image (software.amazon.awssdk.services.rekognition.model.Image)1 RekognitionException (software.amazon.awssdk.services.rekognition.model.RekognitionException)1