pythonamazon-web-servicesboto3amazon-rekognition

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?


Solution

  • 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:

    zoomed_out

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

    But,

    enter image description here

    Now, not so obvious.

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