我正在尝试将 and 转换AWS Rekognition Image
为 java BufferedImage
。为此,我需要 AWS 映像中的字节数组。但是,当我调用该getBytes
方法时,它返回 null 而不是返回ByteBuffer
. 我的代码如下:
//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;
}
...
输入图像只有 80KB 大小,不确定大小是否重要。