Update – 16/Dec/2019: There is now an easier way to install Dlib from the official pip package. Check out the new tutorial How to Build and Install the Latest Version of Dlib on Anaconda on Windows
Dlib is a Machine Learning library, primarily written in C++, but has a Python package also. It has many useful and optimized algorithms useful for machine learning, linear algebra, data structures, image processing, and much more available out-of-the-box.
“Dlib is a modern C++ toolkit containing machine learning algorithms and tools for creating complex software in C++ to solve real world problems. 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. Dlib’s open source licensing allows you to use it in any application, free of charge.” – dlib.net
One of the most popular features in Dlib is Facial Landmark Detection. Dlib installation ships with a pre-trained shape predictor model named shape_predictor_68_face_landmarks.dat, which as the name suggests, is trained to detect 68 facial keypoints including eyes, eyebrows, mouth, nose, face outline, etc.
|Dlib’s Facial Landmark Detection in action
(Make sure to unzip the .bz2 file once you download it)
Of course, Dlib is capable of much more than face landmark detection. I’m hoping to dig into some cool features of Dlib in later posts.
But first, we need to install it.
The Dlib homepage suggests using pip to install the Dlib Python Interface,
pip install dlib
But, what it doesn’t clearly say is the dependencies that are required to install it. You will need to have CMake installed with a C++ compiler for the python package to install.
Now, that’s probably not a problem on Linux – just have CMake and GCC packages installed and you’re done.
On Windows, however, it’s a different story.
I have attempted multiple times to get the compilation working. My first attempt was using CMake Windows binaries with MinGW for C++ compiling. But unfortunately, I wasn’t able to get it working with MinGW.
(I later found out that I could make the pip install work by having Visual Studio installed with CMake. More on that later)
After several attempts, I thought of checking whether there are any Anaconda packages for Dlib. While there were no official Dlib conda packages, I was able to find a pre-built Windows binary package for Dlib on Anaconda.org
. You can check it out here: https://anaconda.org/conda-forge/dlib
You can install the conda-forge Dlib package by running,
conda install -c conda-forge dlib
Conda-forge has made sure to resolve all the dependency conflicts, so I had no issues with the installation. They have pre-built binaries for Windows, Linux, and Mac OS, and Python 2.7 through 3.8. The current package (at the time of this writing) is based on Dlib v19.19
If you do need the latest version, however, you can get the pip install working by using Visual Studio as the C++ compiler coupled with CMake on Windows. Check out the tutorial here: How to Build and Install the Latest Version of Dlib on Anaconda on Windows.
Dlib has a lot of awesome features. Once you get to know a little bit of the internals of the Dlib Python interface, it can be flexible enough to be combined with other libraries such as OpenCV. Check here to see my tutorial on How to combine Dlib’s Face Landmark Detection with OpenCV
How to Build and Install the Latest Version of Dlib on Anaconda on Windows
Getting Dlib Face Landmark Detection working with OpenCV
Extracting individual Facial Features from Dlib Face Landmarks
Build Deeper: The Path to Deep Learning
Learn the bleeding edge of AI in the most practical way: By getting hands-on with Python, TensorFlow, Keras, and OpenCV. Go a little deeper…
Get your copy now!