Skip to content

Instantly share code, notes, and snippets.

@lewcpe
Created November 26, 2017 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lewcpe/ef0f0782232a771a81e7dcfc790a42bd to your computer and use it in GitHub Desktop.
Save lewcpe/ef0f0782232a771a81e7dcfc790a42bd to your computer and use it in GitHub Desktop.
Index Faces from source folder with AWS Rekognition
#!/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