Face detection using dlib in Python

"Dlib is a modern C++ toolkit that contains machine learning algorithms and tools for creating complex software." It allows you to run many tasks directly in Python. One example is face detection.

Installing dlib is not as simple as just doing a "pip install dlib" because to properly configure and compile dlib, you first need to install additional system dependencies. If you follow the steps described here, it should be easy to get dlib up and running. (In this article, I'll show you how to install dlib on Mac, but if you're using Ubuntu, be sure to check out the links to the related resources section.)

Face detection using dlib in Python

The first thing you need to determine is that you have installed and updated Hombrew. If you need to install it, paste it into the terminal:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Or, if you need to update Hombrew, enter the following:

$ brew update

You can now use Homebrew to install CMake, Boost.Python, and the two dependencies needed to properly configure and compile dlib on your system:

$ brew install cmake $ brew install boost-python

Finally, you need to manually download and install XQuartz.

You are now ready to install dlib. We will do this by first creating an isolated virtual environment for this project. I will use virtualenv, but you can use any virtual environment tools you are familiar with, including Python's venv module. The scikit-image library is needed to read the image file we will pass to dlib later, so we also need pip to install it:

$ virtualenv venv_dlib

$ source venv_dlib / bin / acTIvate

$ pip install scikit-image

$ pip install dlib

That's it. With this, you should have available the dlib.

Dlib

Dlib offers different face detection algorithms. What I will use here is a CNN-based face detector. You can download the pre-training model: https://github.com/davisking/dlib-models. Because of the high computational cost of using this model, it is best to execute the following code on the GPU. Using the CPU is fine, but it will be slower.

To run face detection code in the following points, I recommend first installing two more libraries in a virtual environment. These libraries will make it easier to interact with the code and visualize the results:

$ pip install matplotlib

$ pip install jupyterlab

After installing the library, you need to ensure that:

Download the pre-training model (http://dlib.net/files/mmod_human_face_detector.dat.bz2) and store it in the project's root directory

Create a new directory named 'faces' in which to store the .jpg with faces that you want to detect.

With this, you are finally ready to start detecting faces in the picture! You can do this by running the following code in Jupyter Notebook

Face detection using dlib in Python

result

After running the code, you should see blue squares around the face in the image. If you ask me, considering that we only wrote a few lines of code, this is great!

Composite Terminal Block

The composite terminal is a typical representative of the connector (CONNECTOR), which is composed of a plug (female) and a socket (male) to realize the connection function. For the transfer of voltage, current and signal, this series is characterized by safe, reliable and stable contact, and is mainly used in electric power, communication, industrial control and other industries.

Composite Terminal Block

composite terminal block,component terminal block,composite terminal block adapter

Sichuan Xinlian electronic science and technology Company , https://www.sztmlchs.com