Alex Chesters

Software Engineer based in the North West of England

github twitter linkedin rss
Hack Week 2017 - AFK
May 9, 2017
2 minutes read

For the week commencing 1st May I took part in a hack week at work. I’ve been working with Amazon Web Services both professionally and personally for the last two years or so, but I hadn’t had a great deal of experience outside of EC2 or S3. I chose to spend the week hacking with the lesser-known Amazon services.

One such service is Amazon Rekognition, a deep learning-based image recognition service. Rekognition has various features such as Object and Scene Detection, Image Moderation and Face Comparison. For my hack I chose only to utilise Face Comparison, and thus afk was born.

afk is a simple Python program that detects when your have moved away from your screen and locks your system. It works by using imagesnap, a command-line tool for OS X that allows you to control video devices, such as web cams. afk works by taking a picture using your device’s default camera and using Rekognition to determine if your face is in that picture. If it is, the process starts again; if it isn’t, the screen will be locked and the program will exit.

afk utilises Amazon’s Python SDK Boto 3 to interact with the rekognition API. As a result the amount of code I needed to write (28 lines) was miniscule. The image comparison itself only required 12 lines of Python.

import boto3

client = boto3.client('rekognition', region_name='eu-west-1')

def compare_faces(source_image_path, target_image_path):
    source_image = open(source_image_path, 'rb')
    target_image = open(target_image_path, 'rb')
    response = client.compare_faces(
        SourceImage={'Bytes': bytearray(},
        TargetImage={'Bytes': bytearray(}
    return response['FaceMatches']

afk is available on my GitHub, feel free to take a look and try it out for yourself and let me know what you think!

Back to posts

comments powered by Disqus