I am trying to convert and AWS Rekognition Image
to java BufferedImage
. In order to do this I need the byte array from the AWS Image. However, when I call the getBytes
method it returns null instead of returning ByteBuffer
. My code is as below:
//Load an Rekognition Image object from S3
Image inputImage = new Image()
.withS3Object(new com.amazonaws.services.rekognition.model.S3Object().withName(key).withBucket(bucket));
DetectFacesRequest request = new DetectFacesRequest().withImage(inputImage).withAttributes(Attribute.ALL);
try {
DetectFacesResult result = amazonRekognition.detectFaces(request);
List<FaceDetail> faceDetails = result.getFaceDetails();
System.out.println("Number of faces: " + faceDetails.size());
int count = 1;
// I do get a number of FaceDetails back which proves that I am reading the image correctly from S3
for (FaceDetail faceDetail : faceDetails) {
BoundingBox faceBox = faceDetail.getBoundingBox();
try {
// Load image
ByteBuffer imageBytes=inputImage.getBytes();
if (imageBytes == null) {
System.out.println("Why is this null?");
return false;
}
...
The input image is only 80KB in size, not sure if size matters.