Face Recognition using OpenCV – Part 1

Face Recognition OpenCV - How to set up virtualenv and install necessary dependencies

Hello everyone, this is going to be an in-depth tutorial on face recognition using OpenCV. OpenCV is one of the most popular free and open-source computer vision library among students, researchers, and developers alike. We are going to use OpenCV version 3.4.0 and Python 3.6 for our purpose. To learn how to build OpenCV 3.4.0 from source (for advanced users), you can follow this tutorial, How to install OpenCV 3.4.0 on Ubuntu 16.04.

Face Recognition, although many times used interchangeably with Face Detection, are two very different terms. Face Detection means that a system is able to identify that there is a human face present in an image or video. And Face Recognition actually establishes whose face it is. Face Detection has several applications such as autofocus in cameras, count how many numbers of faces are in the picture etc. One of the applications of face detection is face recognition. Although recently made famous by the iPhone X’s Face ID, face recognition is not a new thing. In this tutorial series, we are going to learn how can we write and implement our own program in python for face recognition using OpenCV. I will be dividing the tutorial series into three parts:

  1. How to set up virtualenv and install necessary dependencies?
  2. Face Detection and Face Recognition using OpenCV – training 
  3. Face Recognition using OpenCV – fetching data from SQLite

How to set up virtualenv and install necessary dependencies?

In this part, we will be discussing the topic, “How to set up virtualenv and install necessary dependencies”. Why python virtual environment is needed has already been discussed in this another post here so I’m not going to do that here. Let’s get started with how we can set up virtualenv and install necessary dependencies in python 3.6. The easiest way is installing through python pip package. To install virtualenv through pip, simply type:

pip3 install --upgrade virtualenv

Once the virtualenv is installed, you can create separate virtual environments for each of your projects. Simply go to the project directory and type:

virtualenv opencvenv

You will see a message in your terminal like:

Installing setuptools, pip, wheel…done.

In a newly created virtualenv there will be an activate shell script. This resides in /bin/, so you can run:

source opencvenv/bin/activate

Now, we are ready to install necessary dependencies. The list of dependencies we will be needing for our project are as follows:

  1. OpenCV
  2. OpenCV-contrib
  3. SQLite
  4. numpy
  5. pillow

To install these dependencies, you can use the commands below:

pip3 install opencv-python

pip3 install opencv-contrib-python

pip3 install Pillow

SQLite is available by default on python 3 so you do not need to install it. Also, numpy is installed automatically while installing opencv-python. Now that we have installed all the necessary dependencies, we are ready to create our own face recognition system using OpenCV. We will learn how to detect faces and record and train the faces in the next part of the tutorial.

 

2 Trackbacks & Pingbacks

  1. 1 – Face Recognition Tutorial Using OpenCV 3.4.0
  2. Face Recognition – Python – OpenCV – Just Make Stuff

Leave a Reply

Your email address will not be published.




This site uses Akismet to reduce spam. Learn how your comment data is processed.