【发布时间】:2023-03-16 17:08:01
【问题描述】:
我正在使用 AWS Rekognition 构建人脸识别应用程序。我还想向用户显示与我的输入图像匹配的图像。当我们索引它们时,AWS 是否也会保存图像?如果是,我怎样才能得到该图像?
如果没有,我想这样做。我可以将图像保存到与 ExternalImageId 同名的 S3 中,这样当检测到人脸时,我会从 Rekognition 读取外部 id 并从 S3 中获取它。
如果有比这更好的方法,请告诉我。
我正在使用以下代码来索引集合中的图像:
import boto3
from PIL import Image
import io
import time
image1 = 'images/haad2.jpg'
client = boto3.client('rekognition')
image = Image.open(image1)
stream = io.BytesIO()
image.save(stream, format="JPEG")
image_binary = stream.getvalue()
response = client.index_faces(
Image={
'Bytes': image_binary
},
CollectionId='root_faces_data',
ExternalImageId=str(time.time()),
DetectionAttributes=[
'ALL',
]
)
print(response)
下面的代码可以查看集合中是否存在人脸:
import boto3
import io
from PIL import Image
client = boto3.client('rekognition')
image1 = 'images/haad2.jpg'
client = boto3.client('rekognition')
image = Image.open(image1)
stream = io.BytesIO()
image.save(stream, format="JPEG")
image_binary = stream.getvalue()
response = client.search_faces_by_image(
CollectionId='root_faces_data',
Image={
'Bytes': image_binary
},
MaxFaces=10,
FaceMatchThreshold=90
)
print(response)
这是 search_faces_by_image 的输出:
{
'SearchedFaceBoundingBox': {
'Width': 0.2646464705467224,
'Height': 0.39817628264427185,
'Left': 0.3186868727207184,
'Top': 0.23252280056476593
},
'SearchedFaceConfidence': 99.9957275390625,
'FaceMatches': [
{
'Similarity': 99.98405456542969,
'Face': {
'FaceId': '5bc98595-7d30-4447-b430-4c0fd8f1b926',
'BoundingBox': {
'Width': 0.2646459937095642,
'Height': 0.39817601442337036,
'Left': 0.31868699193000793,
'Top': 0.23252299427986145
},
'ImageId': '8e631731-4a0c-513d-be32-dbfe3ae5e813',
'ExternalImageId': '1534576206.8314612',
'Confidence': 99.9957046508789
}
}
],
'FaceModelVersion': '3.0',
'ResponseMetadata': {
'RequestId': 'eca4bea6-a2b5-11e8-9345-a5eddf19f47f',
'HTTPStatusCode': 200,
'HTTPHeaders': {
'content-type': 'application/x-amz-json-1.1',
'date': 'Sat, 18 Aug 2018 07:12:09 GMT',
'x-amzn-requestid': 'eca4bea6-a2b5-11e8-9345-a5eddf19f47f',
'content-length': '553',
'connection': 'keep-alive'
},
'RetryAttempts': 0
}
}
【问题讨论】:
标签: amazon-web-services amazon-s3 aws-sdk amazon-rekognition