以下脚本允许一次仅将一个图像添加到集合中。
如何将整个S3存储桶添加到集合中?
if __name__ == "__main__":
bucket='bucket'
collectionId='MyCollection'
photo='photo'
client=boto3.client('rekognition')
response=client.index_faces(CollectionId=collectionId,
Image={'S3Object':{'Bucket':bucket,'Name':photo}},
ExternalImageId=photo,
MaxFaces=1,
QualityFilter="AUTO",
DetectionAttributes=['ALL'])
print ('Results for ' + photo)
print('Faces indexed:')
for faceRecord in response['FaceRecords']:
print(' Face ID: ' + faceRecord['Face']['FaceId'])
print(' Location: {}'.format(faceRecord['Face']['BoundingBox']))
print('Faces not indexed:')
for unindexedFace in response['UnindexedFaces']:
print(' Location: {}'.format(unindexedFace['FaceDetail']['BoundingBox']))
print(' Reasons:')
for reason in unindexedFace['Reasons']:
print(' ' + reason)