in code_examples/java_examples/image/java-rotate-image.java [28:96]
public static void main(String[] args) throws Exception {
String photo = "input.png";
//Get Rekognition client
AmazonRekognition amazonRekognition = AmazonRekognitionClientBuilder.defaultClient();
// Load image
ByteBuffer imageBytes=null;
BufferedImage image = null;
try (InputStream inputStream = new FileInputStream(new File(photo))) {
imageBytes = ByteBuffer.wrap(IOUtils.toByteArray(inputStream));
}
catch(Exception e)
{
System.out.println("Failed to load file " + photo);
System.exit(1);
}
//Get image width and height
InputStream imageBytesStream;
imageBytesStream = new ByteArrayInputStream(imageBytes.array());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image=ImageIO.read(imageBytesStream);
ImageIO.write(image, "jpg", baos);
int height = image.getHeight();
int width = image.getWidth();
System.out.println("Image Information:");
System.out.println(photo);
System.out.println("Image Height: " + Integer.toString(height));
System.out.println("Image Width: " + Integer.toString(width));
//Call detect faces and show face age and placement
try{
DetectFacesRequest request = new DetectFacesRequest()
.withImage(new Image()
.withBytes((imageBytes)))
.withAttributes(Attribute.ALL);
DetectFacesResult result = amazonRekognition.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();
}
} catch (AmazonRekognitionException e) {
e.printStackTrace();
}
}