AWS Image getBytes returning null

我的未来我决定 提交于 2019-12-11 14:55:02

问题


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.

来源:https://stackoverflow.com/questions/49801592/aws-image-getbytes-returning-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!