在Amazon Rekognition上通过Python在集合中添加面孔

时间:2019-05-31 02:48:18

标签: python amazon-s3 amazon-rekognition

以下脚本允许一次仅将一个图像添加到集合中。

如何将整个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)

0 个答案:

没有答案