Facial recognition is kind of neat, and had been quite widely use as a quick and dirty way of identifying an individual.
Traditionally to implement Facial recognition we need to:
Identify Faces in an Image
Extract features from the face
Store the features from step 2 in a database, tagged with a name/index
Repeat Step 1 and 2, and compare the new features with all the faces in the database using a classifier then you will get the desired name/index
There’re some great libraries that you can use to implement these steps, such as the “face_recognition” library by Adam Geitgey, which does ease the process relatively. However there’s still a fair bit of work to setup and deploy, with some accuracy issues.
Hence, depending on time limitations and the scpoe of your project you might want to opt for a tool like AWS Rekognition which greatly simplifies and abstracts the steps for doing facial recognition for you.
Just a short note however, AWS rekognition have no GUI available on the AWS web console, hence I’ll also provide the steps to setting up AWS programmatic access in this guide.
Step 1 - Setting up AWS programmatic access
Login to AWS management console
Click on Services > IAM (found under the section “Security, Identity & Compliance).
On the sidebar, click on *Users.
Click on Add user.
Fill in your desired Username, and tick Programmatic access under Select AWS access type, proceed by clicking Next: Permissions
Click Attach exisitng policies directly and Search for AmazonRekognitionFullAccess and tick the option. You can opt for ticking AdministratorAccess if you are using the same user for future projects. Procced by clicking Next: Tags.
Skip the Add tags (optional) page, by clicking Next: Review.
In the Review page, check your options are selected correctly and complete the process by clicking Create user
You’ll be redirected to a Successful page, copy the Access key ID and Secret Access Key and paste it somewhere secure.
For Windows Users
Paste in your Access key ID and Secret Access Key into a file called credentials located inside the folder
%USERPROFILE%/.aws
Full path:
%USERPROFILE%/.aws/credentials
following the format
[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
For Linux Users
Paste in your Access key ID and Secret Access Key into a file called credentials located inside the folder
~/.aws
Full path:
~/.aws/credentials
following the format
[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Step 2 : setting up the python script
Download the code from this gist
import the relevant libraries
pip install boto3 pillow
point the function add2col (line 41) and check_face (Line 42) to your image path(only one face per image), and type in the person’s name replacing ‘PersonNAME’
run if the console prints back the same name you typed in, everything is working
Conclusion
To build your own projects just use the add2col and check_face functions as you see fit, what they do is pretty self-explanatory.
Do note that rekognition doesn’t store actually images in it’s collections it just store the extracted features and metadata.
The data we send to Rekognition is a JPEG file but encoded in a binary stream