0

I am testing Image Recognition from was. So far good. What I am having problems with is indexing faces in the CLI. I can index one at the time, but, I would like to tell AWS to index all faces in a bucket. To index a face one at the time I call this:

aws rekognition index-faces --image "S3Object={Bucket=bname,Name=123.jpg}" --collection-id "myCollection" --detection-attributes "ALL" --external-image-id "myImgID"

How do I tell it to index all images in the "name" bucket?

I tried this:
aws rekognition index-faces --image "S3Object={Bucket=bname}" --collection-id "myCollection" --detection-attributes "ALL" --external-image-id "myImgID"

no luck.

4

2 回答 2

2

您目前无法在一个 index-faces 调用中索引多个面。在存储桶上调用 get-objects 然后循环遍历结果的脚本将完成您想要的。

于 2017-09-19T16:06:41.920 回答
0

万一它在未来对任何人有所帮助,我也有类似的需求,所以我编写了这个 Python 3.6 脚本来完全按照@chris-adzima 的建议去做,并从 lambda 函数中执行它。

import boto3
import concurrent.futures

bucket_name = "MY_BUCKET_NAME"
collection_id = "MY_COLLECTION_ID"

rekognition = boto3.client('rekognition')
s3 = boto3.resource('s3')
bucket = s3.Bucket(bucket_name)


def handle_image(key):
    rekognition.index_faces(
        CollectionId=collection_id,
        Image={
            'S3Object': {
                'Bucket': bucket_name,
                'Name': key
            }
        }
    )


def lambda_handler(event, context):
    pic_keys = [o.key for o in bucket.objects.all() if o.key.endswith('.png')]
    with concurrent.futures.ThreadPoolExecutor() as executor:
        executor.map(handle_image, pic_keys)
于 2018-03-26T09:47:42.660 回答