Error on CompareFacesRequest as part of AWS s Rekognize on Android

0 votes

I apologize if my question is not worded properly, I don't post here very often.

I am having difficulty with launching my request to match 2 faces in 2 different images using Amazon Web Services on my Android application. My code is provided below:

    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

The error I am getting is this:

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)

What is happening in my code is I am converting an image taken from my file path on the android (which is confirmed to be correct) and converting it to a ByteBuffer so that I can pass it Image object created by AWS using withBytes. I did the same for another ByteBuffer, except I converted a BitMap to a ByteBuffer instead (this is not shown in the code). Through debugging I have logged and found that both ByteBuffers are non-empty and fully functional. I have also already tried passing the images in the CompareFacesRequest constructor instead of using the withSource and withTarget image methods. I have also tried calling getBytes on both the Image objects to see if the ByteBuffers really did pass through.

The error hints at me that I am passing 2 empty Image objects with the request, hence it says that there has to be one or more bytes to pass in the Image objects. But I am not sure this is the case. I can't for the life of me figure out why this is happening, it seems to work everywhere else. I would really really appreciate if someone could help me and determine an answer

Oct 1, 2018 in AWS by bug_seeker
• 15,520 points
2,251 views

2 answers to this question.

0 votes

When you mention in your post that you converted a bitmap to a byte buffer, was the source image a ".bmp" file? Can you share that code as well, to help debug your issue?

Please note that Rekognition supports only PNG and JPEG file formats ( see https://docs.aws.amazon.com/rekognition/latest/dg/limits.html).

answered Oct 1, 2018 by Priyaj
• 58,090 points
0 votes
do you get ans?????
answered May 8, 2019 by Gajendra

Related Questions In AWS

0 votes
1 answer

if instance is a part of some AutoScaling Group in AWS or not ?

You can run this command below on ...READ MORE

answered Jun 2, 2018 in AWS by Cloud gunner
• 4,670 points
1,431 views
0 votes
1 answer

A strange spark ERROR on AWS EMR

Those warning messages can be suppressed by ...READ MORE

answered Jul 13, 2018 in AWS by Flying geek
• 3,280 points
1,426 views
0 votes
1 answer
0 votes
1 answer

AWS S3 uploading hidden files by default

versioning is enabled in your bucket. docs.aws.amazon.com/AmazonS3/latest/user-guide/….... the ...READ MORE

answered Oct 4, 2018 in AWS by Priyaj
• 58,090 points
5,387 views
–1 vote
1 answer

How to decrypt the encrypted S3 file using aws-encryption-cli --decrypt

Use command : aws s3 presign s3://mybucket/abc_count.png you get ...READ MORE

answered Oct 22, 2018 in AWS by Priyaj
• 58,090 points
4,825 views
0 votes
1 answer

Import my AWS credentials using python script

Using AWS Cli  Configure your IAM user then ...READ MORE

answered Nov 16, 2018 in AWS by Jino
• 5,810 points
2,557 views
0 votes
2 answers
0 votes
1 answer

Getting memory leak error on AWS EMR - Saving Dataframe into hive external table on S3 -

You can start by creating  a temp ...READ MORE

answered Aug 9, 2018 in AWS by Priyaj
• 58,090 points
1,269 views
+1 vote
1 answer

Can we use AWS Public DNS as Domian name to enable https on our instance

I don't believe you can get a ...READ MORE

answered Aug 23, 2018 in AWS by Priyaj
• 58,090 points
699 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP