How to get started with OpenCV and Dlib for face detection in Windows 10.

Ipsita Mazumder
3 min readOct 19, 2020

The future belongs to those who learn new skills and combine them in creative ways.”

-Robert Greene

In this time of pandemic when things have become both mentally and physically traumatic for us ,I feel we should let our skills become our distraction and our haven, so I came up with this article on a topic where most of the starters find themselves stuck.

I am going to write how to set up your personal computer to make it ready for face detection.

Considering that you have a little bit of idea about machine learning, python, and how face recognition works, I hope that you will find this article useful for getting started with confidence.

First of all we are going to use the pip package manager, if you are wondering why not use conda (another package manager) which is pre-compiled and easier to install ? This is because face_recocognition package can be installed using only pip, and it’s inconvenient to install some packages using pip and others using conda.

Hoping that you have already installed python and upgraded both python and pip to their latest version in your system to avoid unnecessary warnings.

Why do we need OpenCV and Dlib ?

Both are open source libraries that accelerate machine learning through a variety of algorithms for processing images and video's.

Follow the below given order of installation of different software's.

Setting up your system :

  • Installing OpenCV : Open command prompt and type the following command and wait for the system to finish the installation.

pip install opencv-python

Check if OpenCV is correctly installed and perform a version check.

Python

>>>import cv2

>>>print(cv2.__version__)

  • Download Cmake : As dlib was written in C++ , so we need this program for using it. Download the 64 bit Windows 10 version from the official website https://cmake.org/download/ .
  • Install Visual Studio : We definitely need this C++ compiler for executing our CMake program required by the dlib library.

https://visualstudio.microsoft.com/visual-cpp-build-tools/

Make sure to select this red box during your visual studio set up process.

Also make sure that you have added the CMake executable path to the environmental variables.

  1. Go-to Advanced System Settings->Advanced tab->Environment Variables
  2. Click edit

If you are unable to find CMake path, you must add the CMake installed directory like the image given below.

  • Install Cmake : Install the Cmake library .

pip install cmake

  • Install dlib : Install dlib library .

pip install dlib

The above installations , especially visual studio, might take some considerable time , so have patience and free up some memory in your disk before you start the installations if your system doesn’t have sufficient memory !

  • Install face_recognition : Use the command -

pip install face_recognition.

Fork and clone my repository (Here) and run the code in your IDE .

https://github.com/IPSITA2000/Face-Detection-Introduction

Import the necessary files in the IDE , of course you can add your images too !

Possible error that you might encounter while you run the code :

  • module ‘dlib’ has no attribute ‘get_frontal_face_detector’ ERROR.

Make sure that you have not named your file dlib or with any other keywords. If the error still persists you must reinstall the dlib library after you uninstall it.

Hopefully these should resolve your issue !

Last but not the least try to logically analyze each line of the code for better understanding and finally you will be confident enough with your first face detector python code using dlib and openCV.

Thank you!

--

--

Ipsita Mazumder

I write technical blogs to make life easier for other techies .