AWS Image getBytes返回null

时间:2018-04-12 16:24:47

标签: java amazon-web-services aws-sdk aws-java-sdk amazon-rekognition

我正在尝试将AWS Rekognition Image转换为java BufferedImage。为了做到这一点,我需要来自AWS Image的字节数组。但是,当我调用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,不确定尺寸是否重要。

0 个答案:

没有答案