博图AWS识别错误

2024-04-25 07:39:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用AWS rekognition通过pythonbot3来比较人脸,正如AWS文档中所述。在

我的API调用是:

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()

但每次我运行这个程序时,都会出现以下错误:

^{pr2}$

我已经正确地指定了秘密、密钥、区域和阈值。如何清除此错误并使请求调用生效?在


Tags: keyclientawssourcetargetsecretbytesaccess
2条回答

以你打开文件的方式,你不需要转换到bytearray。在

试试这个:

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()

你的代码很好

当涉及到AWS识别时,图像尺寸很重要。在

亚马逊认可的限制

以下是亚马逊认可的限额列表:

  1. 存储为amazons3对象的最大图像大小限制为15mb。在
  2. 高度和宽度的最小像素分辨率为80像素。最大值作为参数传递给API的图像大小为5 MB。在
  3. Amazon Rekognition支持PNG和JPEG图像格式。也就是说,作为各种API操作(如detectLables和indexface)的输入提供的图像必须是受支持的格式之一。在
  4. 单个人脸集合中可以存储的最大面数为100万个。 搜索API返回的最大匹配面为4096。在

来源:AWS Docs

相关问题 更多 >