【问题标题】:AWS rekognition InvalidParameterExceptionAWS rekognition InvalidParameterException
【发布时间】:2019-11-18 20:17:13
【问题描述】:

如果我上传小分辨率较低的图像,我得到 aws rekognition invalid parameter 异常。

见下面的错误

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

我的代码是

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

【问题讨论】:

  • 异常似乎是 InvalidImageFormatException,而不是 InvalidParameterException。文档告诉您,这意味着“不支持提供的图像格式”。它实际上是一个有效的图像吗?它是什么类型的图像(jpeg、png 等)?
  • 是的,实际上它是 png 或 jpeg,但我想我发现问题是由于图像的最小尺寸,如果我们上传模糊图像或小于 100kb 的图像,那么只会出现这个错误,否则它可以工作完美,谢谢 jarmod
  • 图片的最小高度和宽度均为 80 像素。

标签: php amazon-web-services amazon-rekognition


【解决方案1】:

当 indexFaces 无法检测到任何人脸时,将引发此异常。这可能是在图片很小且模糊的情况下,但在其他情况下,例如当没有真实的脸时。您可以尝试先运行 DetectFaces 并检查响应。 类似这样:

$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.
}

您可以在此处找到有关 Detect Faces 的更多信息: https://docs.aws.amazon.com/rekognition/latest/dg/API_DetectFaces.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-30
    • 2018-11-17
    相关资源
    最近更新 更多