Error in Boto AWS Rekognition

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

My API call:

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 every time 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 correctly identified the secret, key, region and threshold. How can I remove this error and make it work with the request?

+4
source share
2 answers

As you open the file, you do not need to drop bytearray.

Try the following:

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()
+1
source

Your code is ok

Image sizes matter when it comes to ReSognition AWS.

Limitations on remarking Amazons

Amazon:

  • , Amazon S3, 15 .
  • 80 . , API, 5 .
  • Amazon Rekognition PNG JPEG. , API, DetectLabels IndexFaces, .
  • , , 1 . API 4096.

: AWS Docs

0

Source: https://habr.com/ru/post/1668603/


All Articles