要添加同一人的额外面孔,您可以使用AWS Rekognition的indexFaces
操作。以下是一个代码示例,演示如何使用AWS SDK for Python(Boto3)进行此操作:
import boto3
# 初始化Rekognition客户端
rekognition_client = boto3.client('rekognition')
# 定义要添加面孔的集合ID
collection_id = 'your-collection-id'
# 定义要添加面孔的图像文件名
image_file = 'your-image-file.jpg'
# 定义要添加面孔的人员ID
person_id = 'your-person-id'
# 定义要添加的面孔的外部ID
external_id = 'your-external-id'
# 执行indexFaces操作
response = rekognition_client.index_faces(
CollectionId=collection_id,
Image={'S3Object': {'Bucket': 'your-bucket-name', 'Name': image_file}},
ExternalImageId=external_id,
DetectionAttributes=['ALL'],
MaxFaces=1,
QualityFilter='AUTO',
FaceAttributes='ALL',
ExternalId=external_id,
MaxResults=1
)
# 获取添加的面孔信息
face_records = response['FaceRecords']
for face_record in face_records:
face_id = face_record['Face']['FaceId']
print(f"Face ID: {face_id} added to person ID: {person_id}")
请确保替换代码中的以下值:
your-collection-id
:您的Rekognition集合ID。your-image-file.jpg
:要添加的面孔的图像文件名。your-person-id
:要添加面孔的人员ID。your-external-id
:要添加的面孔的外部ID。your-bucket-name
:存储图像文件的S3存储桶名称。此代码将使用indexFaces
操作将图像文件中的面孔添加到指定的Rekognition集合中。添加的面孔将与给定的人员ID和外部ID关联起来。成功添加的面孔将返回其Face ID。
请注意,您需要在执行此代码之前安装并配置AWS SDK for Python(Boto3)。