Detect, Analyze, and Compare Faces

with Amazon Rekognition

In this tutorial, you will learn how to use the face recognition features in Amazon Rekognition using the AWS Console. Amazon Rekognition is a deep learning-based image and video analysis service.

As a developer, facial recognition and comparison is a new challenge you will face if you are developing an employee verification system, need to automate video editing, or provide secondary authentication for other applications. To solve this challenge, you could develop your own machine learning model, develop an API, and manage your own infrastructure. This option is expensive, requires advanced knowledge, and is time intensive.

Instead of taking the difficult route, you can use Amazon Rekognition, which can detect faces in an image or video, find facial landmarks such as the position of eyes, and detect emotions such as happy or sad in near real-time or in batches without management of infrastructure or modeling.

In this tutorial, you will use Amazon Rekognition to analyze an image and then compare it to other images to see if the faces are the same.  

This tutorial is a demo of the functionality that is available when using the AWS CLI or the Rekognition API. For production or proof of concept implementations, we recommend using these programmatic interfaces rather than the Amazon Rekognition Console.

This tutorial requires an AWS account

There are no additional charge for Amazon Rekognition. The resources you create in this tutorial are Free Tier eligible. 

More about the Free Tier >>


Step 1. Enter the Amazon Rekognition Console


Open the AWS Management Console, so you can keep this step-by-step guide open. When the screen loads, enter your user name and password to get started. Then type Rekognition in the search bar and select Rekognition to open the service console.

detect-analyze-faces-rekognition-1

( click to enlarge )


Step 2: Analyze Faces

In this step, you will use the facial analysis feature in Amazon Rekognition to see the detailed JSON response you can receive from analyzing one image.


a) To start, select Facial analysis in the panel navigation on the left. This feature allows you to analyze faces in an image and receive a JSON response.

detect-analyze-faces-rekognition-2a
detect-analyze-faces-rekognition-2a

( click to enlarge )


b) Open and save the first sample image for this tutorial here.

652499668
652499668

( click to enlarge )


c) Click the blue Upload button and select the sample image you just saved.

detect-analyze-faces-rekognition-2c
detect-analyze-faces-rekognition-2c

( click to enlarge )


d) Notice that under the Results drop down you can click through and see quick results for each face that was detected.

detect-analyze-faces-rekognition-2d
detect-analyze-faces-rekognition-2d

( click to enlarge )


e) Click on the Response drop down to see the JSON results. Notice that under the emotions results there are three detected emotions: happy, confused, and calm. Happy has a 99.79% confidence rating, while the others are both less than 1%.

As a developer, detecting emotions in images and videos makes it possible to quickly catalog a digital library by emotion. Another use case for detecting emotions is to amplify ad targeting so users receive a personalized experience tailored to the current emotion.

detect-analyze-faces-rekognition-2e

( click to enlarge )

detect-analyze-faces-rekognition-2ee
detect-analyze-faces-rekognition-2ee

( click to enlarge )


Step 3: Compare Faces

In this step, you will use the face comparison feature to see the detailed JSON response from comparing two different images that don't match.


a) Select Face comparison in the panel navigation on the left.


detect-analyze-faces-rekognition-3a

( click to enlarge )


b) Open and save the second sample image for this tutorial here.

 

detect-analyze-faces-rekognition-sample2

( click to enlarge )


c) Click on the blue Upload button for the reference face and select the image you just saved.

 

 

detect-analyze-faces-rekognition-3c

( click to enlarge )


d) Click on the blue Upload button for the comparison face and select our first sample image we used in step 2.

 

 

detect-analyze-faces-rekognition-3d

( click to enlarge )


e) Notice that in Results drop down you can see that our reference wasn’t a match for any of the detected faces in our comparison faces image.


detect-analyze-faces-rekognition-3e
detect-analyze-faces-rekognition-3e

( click to enlarge )


f) Click on the Response drop down to see the JSON results. Notice that the “Similarity” score for each of the detected faces never exceeds 10. The similarity score ranges from 1-100 and the threshold can be adjusted when using the API.

As a developer, comparing faces at scale can be used in applications to track persons of interest, create a face-based employee verification system, or provide a VIP experience to guests staying at a hospitality venue.

 

detect-analyze-faces-rekognition-3f
detect-analyze-faces-rekognition-3f

( click to enlarge )


Step 4: Compare Faces (Again)

In this step, you will use the face comparison feature to see the detailed JSON response from comparing two different images that have a match.


a) Open and save the third and final sample image for this tutorial here.

detect-analyze-faces-rekognition-sample3
detect-analyze-faces-rekognition-sample3

( click to enlarge )


b) Click on the blue Upload button for the reference face and select the image you just saved.

 

detect-analyze-faces-rekognition-4b
detect-analyze-faces-rekognition-4b

( click to enlarge )


c) Notice that the reference face that was compared to our other photo detected a 97% similarity score and detected that all other faces were not a match.


detect-analyze-faces-rekognition-4c
detect-analyze-faces-rekognition-4c

( click to enlarge )


d) Click on the Response drop down to see the details of each comparison.


detect-analyze-faces-rekognition-4d
detect-analyze-faces-rekognition-4d

( click to enlarge )


Congratulations!

You have learned how to use the console to analyze and compare faces. You can also perform this feature using the API so you can operate at scale. Use Amazon Rekognition when you need to perform facial analysis at scale without worrying about infrastructure or training a model for identifying persons of interest, cataloging a digital library, creating a face-based employee verification system, or performing sentiment analysis.