Created
November 26, 2017 14:18
-
-
Save lewcpe/ef0f0782232a771a81e7dcfc790a42bd to your computer and use it in GitHub Desktop.
Index Faces from source folder with AWS Rekognition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""Upload all images and index faces with AWS Rekognition""" | |
import boto3 | |
import logging | |
from os.path import split, splitext | |
def index_faces(collection, files): | |
client = boto3.client('rekognition') | |
for fname in files: | |
logging.debug('Indexing %s', fname) | |
mainname = splitext(split(fname)[-1])[0] | |
image_data = open(fname, 'rb').read() | |
response = client.index_faces( | |
Image={ | |
'Bytes': image_data | |
}, | |
CollectionId=collection, | |
ExternalImageId=mainname | |
) | |
logging.debug("Resp = %s", response) | |
def main(): | |
from glob import glob | |
images = glob('sources/*.jpg') | |
index_faces('twice', images) | |
if __name__ == "__main__": | |
logging.basicConfig(level=logging.DEBUG) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment