在比较不同S3存储桶中的两个图像时,我在这里做错了一些事情。
尽管如此,我仍在比较男性和女性的图像,这将给99%的信心
还是我在声明中遗漏了一些东西
也许这行引起了问题
key_target =“ targett /” +键
或者我的事件代码容易出错,这是我提到我的源存储桶的地方,即使我在下面的用于测试的lambda函数中也提到了它。我还需要纠正什么,以使其在指定范围内返回置信度
from __future__ import print_function
import boto3
from decimal import Decimal
import json
import urllib
print('Loading function')
rekognition = boto3.client('rekognition')
#iot = boto3.client('iot-data')
# --------------- Helper Functions to call Rekognition APIs ------------------
def compare_faces(bucket, key, key_target, threshold=75):
response = rekognition.compare_faces(
SourceImage={
"S3Object": {
"Bucket": 'dacss',
"Name": 'obama.jpg',
}
},
TargetImage={
"S3Object": {
"Bucket": 'targett',
"Name": 'michelle.jpg',
}
},
SimilarityThreshold=threshold,
)
return response['SourceImageFace'], response['FaceMatches']
# --------------- Main handler ------------------
def lambda_handler(event, context):
print("Received event: " + json.dumps(event, indent=2))
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.unquote_plus(event['Records'][0]['s3']['object']
['key'].encode('utf8'))
key_target = "targett/" + key
try:
response = compare_faces(bucket, key, key_target)
print(response)
# mypayload = json.dumps(response)
# iotResponse = iot.publish(
# topic="rekognition/result",
# qos=1,
# payload=mypayload)
# print(iotResponse)
# return iotResponse
print(response)
return response
except Exception as e:
print(e)
print("Error processing object {} from bucket {}. ".format(key,
bucket)
+
"Make sure your object and bucket exist and your bucket is in
the
same region as this function.")
raise e
---------------output-----------------
Response:
[
{
"BoundingBox": {
"Width": 0.7813892960548401,
"Top": 0.15193353593349457,
"Left": 0.1047489121556282,
"Height": 0.8365015387535095
},
"Confidence": 99.99993896484375
},
[]
]
答案 0 :(得分:0)
这些行:
TargetImage={
"S3Object": {
"Bucket": targett,
"Name": obama.jpg,
}
应为:
TargetImage={
"S3Object": {
"Bucket": 'targett',
"Name": key_target,
}
答案 1 :(得分:0)
我认为您在这里有误会
{
'FaceMatches': [
{
'Face': {
'BoundingBox': {
'Height': 0.33481481671333313,
'Left': 0.31888890266418457,
'Top': 0.4933333396911621,
'Width': 0.25,
},
'Confidence': 99.9991226196289,
},
'Similarity': 100,
},
],
'SourceImageFace': {
'BoundingBox': {
'Height': 0.33481481671333313,
'Left': 0.31888890266418457,
'Top': 0.4933333396911621,
'Width': 0.25,
},
'Confidence': 99.9991226196289,
},
'ResponseMetadata': {
'...': '...',
},
}
在这里,置信度得分不显示天气是否与面部匹配,而是表明它在图像中找到了面部。 “相似”表示图像的实际匹配。