import boto3
if __name__ == "__main__":
bucket='MyBucketName'
sourceFile='pic1.jpg'
targetFile='pic2.jpg'
client=boto3.client('rekognition','us-east-1')
response=client.compare_faces(SimilarityThreshold=70,
SourceImage={'S3Object':{'Bucket':bucket,'Name':sourceFile}},
TargetImage={'S3Object':{'Bucket':bucket,'Name':targetFile}})
for faceMatch in response['FaceMatches']:
position = faceMatch['Face']['BoundingBox']
confidence = str(faceMatch['Face']['Confidence'])
print('The face at ' +
str(position['Left']) + ' ' +
str(position['Top']) +
' matches with ' + confidence + '% confidence')
Run Code Online (Sandbox Code Playgroud)
我正在尝试比较存储桶中存在的两个图像,但无论我选择哪个区域,我总是收到以下错误:-
botocore.errorfactory.InvalidS3ObjectException:调用 CompareFaces 操作时发生错误 (InvalidS3ObjectException):无法从 S3 获取对象元数据。检查对象密钥、区域和/或访问权限。
我的存储桶的区域是 us-east-1,我在我的代码中配置了相同的区域。我究竟做错了什么?