Well, thisis an advanced machine learning library that was created to solve complex real-world problems.

Its also worth noting this tutorial might require some previous understanding of the OpenCV library.

40% off TNW Conference!

A comprehensive guide on how to detect faces with Python

Our face has several features that can be identified, like our eyes, mouth, nose, etc.

If you get compiling errors during the installation check that you check the CMake library version youre using.

So, lets get started:

Pretty simple, right?

Article image

After that, we need to pause execution as the window will be destroyed when the script stops.

Thats pretty boring, but now well start coding the good stuff and identify the face in the image.

For this we will use a Dlib function calledget_frontal_face_detector(), pretty intuitive.

Article image

Theget_frontal_face_detector()willreturn adetectorthat is a function we can use to retrieve the faces information.

Each face is an object that contains the points where the image can be found.

But we still need to do some work to extract all the features.

Article image

Lets work on that next.

Will the next steps be just as east?

The short answer is yes!

Article image

Lets see how the code looks now:

Like before, were always building on the same code.

Now, were using our predictor function for each face to find the landmarks.

But theres still something a little strange, like whats the number 27 doing there?

Article image

If everything worked out correctly, you should see a green dot between the eyes in the face.

Were getting really close, lets now render all the points instead of just the one:

Tada!

Magic:

But what if youre not interested in all the points?

Article image

Step 4: Real-time detection

Yes, you read it right!

And yes its probably what you are thinking!

The next step is to hook up our webcam and do real-time landmark recognition from your video stream.

Article image

OpenCV and DLib are powerful libraries that simplify working with machine learning and computer vision.

This article was originally published onLive Code StreambyJuan Cruz Martinez, founder and publisher of Live Code Stream.

Sign up for updates on everything related to programming, AI, and computer science in general.

Article image

Also tagged with

Article image

Article image

Article image

Article image

Article image

Article image

Article image

Article image

Article image