简体   繁体   中英

Error in Boto AWS Rekognition

I am trying to compare faces using AWS Rekognitionthrough Python boto3, as instructed in the AWS documentation.

My API call is:

client = boto3.client('rekognition', aws_access_key_id=key, aws_secret_access_key=secret, region_name=region )

source_bytes = open('source.jpg', 'rb')
target_bytes = open('target.jpg', 'rb')

response = client.compare_faces(
    SourceImage = {
        'Bytes':bytearray(source_bytes.read())
    },
    TargetImage = {
        'Bytes':bytearray(target_bytes.read())
    },
    SimilarityThreshold = SIMILARITY_THRESHOLD
)

source_image.close()
target_image.close()

But everytime I run this program,I get the following error:

botocore.errorfactory.InvalidParameterException: An error occurred (InvalidParameterException) when calling the CompareFaces operation: Request has Invalid Parameters

I have specified the secret, key, region, and threshold properly. How can I clear off this error and make the request call work?

Your code is perfectly fine,

image dimensions matters when it comes to AWS Rekognition.

Limits in Amazon Rekognition

The following is a list of limits in Amazon Rekognition:

  1. Maximum image size stored as an Amazon S3 object is limited to 15 MB.
  2. The minimum pixel resolution for height and width is 80 pixels.Maximum images size as raw bytes passed in as parameter to an API is 5 MB.
  3. Amazon Rekognition supports the PNG and JPEG image formats. That is, the images you provide as input to various API operations, such as DetectLabels and IndexFaces must be in one of the supported formats.
  4. Maximum number of faces you can store in a single face collection is 1 million. The maximum matching faces the search API returns is 4096.

source: AWS Docs

The way you are opening the file, you don't need to cast to bytearray.

Try this:

client = boto3.client('rekognition', aws_access_key_id=key, aws_secret_access_key=secret, region_name=region )

source_bytes = open('source.jpg', 'rb')
target_bytes = open('target.jpg', 'rb')

response = client.compare_faces(
    SourceImage = {
        'Bytes':source_bytes.read()
    },
    TargetImage = {
        'Bytes':target_bytes.read()
    },
    SimilarityThreshold = SIMILARITY_THRESHOLD
)

source_image.close()
target_image.close()

For those still looking for answer,

I had the same problem, while, @mohanbabu pointed to official docs for what should go in to compare_faces , what I realised is that compare_faces looks for faces in both SourceImage and TargetImage . I confirmed this by first detecting faces using aws's detect_faces and passing deteced faces to compare_faces .

compare_faces failed almost all the time when face detected by detect_faces was a littile obscure.

So, to summerize if any of your SourceImage or TargetImage is tightly cropped to face AND that face is not instantly obvious, compare_faces will fail.

There can be other reason but this observation worked for me.

ex:

缩小

In the above image you can fairly confidently say there is a face in the middle

But,

在此处输入图片说明

Now, not so obvious.

This was the reason for me atleast, check both your images and you should know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM