import boto3
import os
import codecs
import json
rekognition = boto3.client('rekognition')
bucket = "my-bucket"
photos = ["photo1.jpg", "photo2.jpg", "photo3.jpg"]
manifest_filename = "my-manifest-file.json"
manifest = []
for photo in photos:
full_path = os.path.join(bucket, photo)
manifest.append({"source-ref": full_path})
#Write the manifest to disk
with codecs.open(manifest_filename, 'w', encoding="utf8") as json_file:
json_file.write(json.dumps(manifest, ensure_ascii=False))
#Upload the manifest file and the images to Amazon S3
s3 = boto3.resource('s3')
s3_bucket = s3.Bucket(bucket)
s3_bucket.upload_file(manifest_filename, manifest_filename)
for photo in photos:
s3_bucket.upload_file(photo, photo)
#Start the search using Amazon Rekognition
response = rekognition.start_face_search(Video = {"S3Object": {"Bucket": bucket, "Name": "my-video.mp4"}},
FaceMatchThreshold = 80,
CollectionId = "my-collection-id",
JobTag = "my-job-tag",
NotificationChannel = {"RoleArn": "arn:aws:iam::0123456789012:role/my-notification-role", "SNSTopicArn": "arn:aws:sns:us-east-1:0123456789012:my-topic"})
job_id=response['JobId']
print('Started job:' + job_id)
在这个例子中,我们制作了一个搜索视频中人脸的示例,其中上传了多个图像并使用了一个manifest文件。该文件是包含每个图像S3位置的JSON文件。请注意manifest文件必须少于或等