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);
}
}
Aggregations