【问题标题】:Error on CompareFacesRequest as part of AWS's Rekognize on Android作为 AWS 在 Android 上的 Rekognize 的一部分,CompareFacesRequest 出现错误
【发布时间】:2018-03-20 09:36:28
【问题描述】:

如果我的问题措辞不当,我深表歉意,我不经常在这里发帖。

我在我的 Android 应用程序上使用 Amazon Web Services 发起匹配 2 张不同图像中的 2 张面孔的请求时遇到了困难。我的代码如下:

    CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
                getApplicationContext(), // Context
                "xxxxxxx", // Identity Pool ID
                Regions.US_EAST_1 // Region
        );

    AmazonRekognitionClient client = new AmazonRekognitionClient(credentialsProvider);

    ByteBuffer buffer = ByteBuffer.allocate(croppedBitmap.getByteCount()); //Create a new buffer
        croppedBitmap.copyPixelsToBuffer(buffer); //Move the byte data to the buffer

try {
    //get first image from phone
    File dhruv = new File("/sdcard/temp/dhruv.jpg");
    InputStream inputStream = new 
    FileInputStream(dhruv.getAbsolutePath().toString());

    //convert to ByteBuffer
    ByteBuffer byteBuffer = 
    ByteBuffer.wrap(IOUtils.toByteArray(inputStream));
    Log.d("lol", Arrays.toString(byteBuffer.array()));

    Image image = new Image();
    Image image2 = new Image();
    image.withBytes(buffer);
    image2.withBytes(byteBuffer);

    CompareFacesRequest compare = new CompareFacesRequest();
    compare.withSourceImage(image);
    compare.withTargetImage(image2);

    CompareFacesResult result = client.compareFaces(compare);
    result.getFaceMatches();
} catch(...) {} // catched the error

我得到的错误是这样的:

3247/com.busradeniz.detection D/lol: 1 validation error detected: Value 
'java.nio.HeapByteBuffer[pos=0 lim=0 cap=0]' at 'sourceImage.bytes' failed 
to satisfy constraint: Member must have length greater than or equal to 1 
(Service: AmazonRekognition; Status Code: 400; Error Code: 
ValidationException; Request ID: a0489079-2c17-11e8-b8b8-23c9eaea153d)

我的代码中发生的事情是我正在转换从我在 android 上的文件路径获取的图像(已确认是正确的)并将其转换为 ByteBuffer 以便我可以传递 AWS 使用 withBytes 创建的图像对象.我对另一个 ByteBuffer 做了同样的事情,除了我将 BitMap 转换为 ByteBuffer(代码中没有显示)。通过调试,我记录并发现两个 ByteBuffers 都是非空的并且功能齐全。我也已经尝试在 CompareFacesRequest 构造函数中传递图像,而不是使用 withSource 和 withTarget 图像方法。我还尝试在两个 Image 对象上调用 getBytes 以查看 ByteBuffers 是否真的通过了。

该错误提示我正在通过请求传递 2 个空 Image 对象,因此它表示必须有一个或多个字节才能传递 Image 对象。但我不确定情况是否如此。我一生都无法弄清楚为什么会发生这种情况,它似乎在其他任何地方都有效。如果有人可以帮助我并确定答案,我将非常感激??

非常感谢, 德鲁夫

【问题讨论】:

    标签: java android amazon-web-services amazon-s3 knox-amazon-s3-client


    【解决方案1】:

    当您在帖子中提到您将位图转换为字节缓冲区时, 源图像是“.bmp”文件吗?您能否也分享该代码以帮助调试您的问题?

    请注意,Rekognition 仅支持 PNG 和 JPEG 文件格式(请参阅 https://docs.aws.amazon.com/rekognition/latest/dg/limits.html)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-06
      • 2017-09-12
      • 2021-06-13
      • 1970-01-01
      • 2017-12-19
      • 2020-11-10
      • 1970-01-01
      • 2017-09-10
      相关资源
      最近更新 更多