Face Recognition:

How to use the Face-Recognition library in Python

By Alaina Ahuja August 9th 2020

Face recognition is an amazing technology that is starting to become more and more popular in our apps and cell phones, and now there’s a new python library that let’s us incorporate face recognition into our own python applications!

In this tutorial, I’m going to be teaching you some of the most common face-recognition functions and then provide code for one of my face recognition python programs.

First we need to install face-recognition:

To install the face-recognition library on your machine, you can use the following command in the terminal:

Here are some common lines you can use in your face recognition programs and what they do:

Obviously, this line is to import the library into your program
This line tells face-recognition which picture you want it to analyze.

This line returns a list of encodings face-recognition will use to detect faces. Of course if you saved the previous line in a variable, put the name of that variable in place of “face_recognition.load_image_file(“your_file.jpg”)”
This line is for comparing to faces and returns a boolean response. If it’s true, that means that the two pictures it’s comparing are of the same person. The third parameter, is of the tolerance. Depending on how high the tolerance is, the more closely face-recognition checks for those tiny details of the face. I found that 0.5 is the perfect tolerance for most pictures. Too much or too little tolerance will cause your program to break, so I would recommend to go with 0.5. If that doesn’t work, you can experiment with different tolerances.

If you want to see some sample face-recognition applications, visit my face-recognition repository at

https://github.com/alainaahuja/face_recognition

Close Bitnami banner
Bitnami