Dlib library – Introduction and Installation

Its often difficult to implement some machine learning libraries and computer vision algorithms from scratch. Yes, I do believe in implementing from scratch, since the satisfaction of learning is remarkable, but when it comes to actually complete a task within short span of time or prototype a project’s feasibility issue, opting a library or API makes sense.

Dlib is a collection of miscellaneous algorithms in Machine Learning, Computer Vision, Image Processing, and Linear Algebra. Most of the library is just header files that you can include in your C++ application. And if you are python programmer, no worries, it has python API as well ready to use. It is used in both industry and academia in a wide range of domains including robotics, embedded devices, mobile phones, and large high performance computing environments.
For additional information, follow dlib.net

Major features:

  • Detailed Documentation – You will find well commented example codes, that are enough to understand functions
  • Machine Learning Algorithms
  • Numerical Algorithms
  • Graphical Model Inference Algorithms
  • Image Processing
  • Networking
  • Graphical User Interfaces
  • Data Compression and Integrity Algorithms

When it comes to documentation, the functions and libraries are well defined in its documentation. Moreover, Dlib comes with more than 100 example codes, well commented, to practice all most all of its features stated above. I have been through I Image processing and Machine learning libraries, and they are actually very easy to use. Though, I personally feel that process of implementing some codes and algorithms are not so well described ( functions are described at best though), it might become cumbersome for beginners to go through all example codes, read between the lines to understand the process they need to undertake to implement algorithm. So with some series of posts on this blog, I will be discussing the process for implementing some algorithms for better understanding for beginners to this collection.

This Section will include:

  • Using face detection algorithm – based on HOG feature and image pyramid with cascade classifier
  • Training your own face detection algorithm classifier
  • Using object detection algorithm – based on HOG feature
  • Training your own object detection algorithm
  • Comparing Opencv’s Object detection ( based on Haar like feature from Viola – Jones ) and Dlib’s Object detection ( based on Histogram of oriented gradients features and Image pyramid )
  • Facial Landmark detection and Face pose estimation.

This list will be updated time to time as I will add posts for other examples

Installing Dlib in Linux based systems

I assume that basic github commands and cmake commands are well understood. Still I will be pointing out important aspects if needed in between.

Clone the official github repository of Dlib at convenient place :

Build Example , the actual directory for learning its features and functions

You will observe that build folder will be filled with all executables to cpp files in examples directory. Do remember that the CMakeLists.txt exists in examples and not within build. Make a copy of an example cpp file, modify it, modify examples/CMakeLists.txt accordingly mentioned in txt and compile again using the instructions above. A sensible process to learn them in organized manner.

For python programmers, go to the base folder of the dlib repository and run

That should compile and install the dlib python API on your system.

To get yourself elated by fact if you have successfully installed Dlib on your system, a short example for detecting facial landmark can be implemented. Beforehand be ready with your webcam connected to your system and its video id ( 0, 1, 2 or whatever it is).

#Example – Facial Landmark Detector

We need to download the model which is training file to this example. Once downloaded, it will be then also used by other examples in repository as input ( it will be well known when you will go through code of other examples line to line)

The extraction process with tar might give error in some systems. Don’t worry. Just extract the file manually using archive manager , that’s all. You must see something like this features marked in green on your face ;



If you want to run it on a single image, you can try

landmarkThis tool is powerful that it works even under partial occlusions. Look at the example above.

I hope this post helped to get known to Dlib, motivation for its use and installing it the easy way!

Leave a Reply, I generally respond quickly

%d bloggers like this: