2
votes

I got aws rekognition invalid parameter Exception, if I upload small lower resolution image.

see below error

https://rekognition.us-west-2.amazonaws.com` resulted in a `400 Bad Request` response: {"__type":"InvalidImageFormatException","Message":"Request has invalid image format"} InvalidImageFormatException (client): Request has invalid image format - {"__type":"InvalidImageFormatException","Message":"Request has invalid image format"}' GuzzleHttp\Exception\ClientException: Client error: `POST https://rekognition.us-west-2.amazonaws.com` resulted in a `400 Bad Request` response: {"__type":"InvalidImageFormatException","Message":"Request has invalid image format"} in /var/www/vhosts/harvest.io.farm/aws/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:111 Stack trace: #0 /var/www/vhosts/harvest.io.farm/aws/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(Guz in /var/www/vhosts/harvest.io.farm/aws/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 192

And my code is

$result = $recognizationClient->indexFaces([
            'CollectionId' => getCollectionName( $txtCID ), // REQUIRED
            'Image' => [ // REQUIRED
                'S3Object' => [
                    'Bucket' => $bucket,
                    'Name' => $actual_image_name            
                ],
            ],
        ]);
1
The exception appears to be InvalidImageFormatException, not InvalidParameterException. The docs tell you that this means "The provided image format is not supported." Is it actually a valid image? What type of image is it (jpeg, png, etc)?jarmod
Yeah actually it is png or jpeg, but I think I found the issue it is due to minimum size of image, if we upload blur image or less then 100kb image then only this error comes otherwise it works perfect, Thanks jarmodMitul Patel
The minimum image size is 80 pixels for both height and width.jarmod

1 Answers

0
votes

This exception is thrown when the indexFaces cannot detect any faces. This can be when the picture is small and blurred but in other cases such as when there is not an actual face. You can try to run DetectFaces first and check the response. Similar to this:

$is_face_detected = $aws_rekognition_client->detectFaces([
                'Image' => [
                    'S3Object' => [
                        'Bucket' => $bucket,
                        'Name' => $actual_image_name
                    ]
                ]
            ]);

if (!empty($is_face_detected['FaceDetails'])) {

    $result = $recognizationClient->indexFaces([
            'CollectionId' => getCollectionName( $txtCID )
            'Image' => [
                'S3Object' => [
                    'Bucket' => $bucket,
                    'Name' => $actual_image_name            
                ],
            ],
        ]);

} else {
   // perform notification, etc.
}

There is more you can find about Detect Faces here: https://docs.aws.amazon.com/rekognition/latest/dg/API_DetectFaces.html