Implement Face Detection Using Python

Implement Face Detection Using Python

In this post, you'll learn how to build a face detection program using Python for yourself in less than 3 minutes.

Originally published by Sabina Pokhrel at

Face detection is one of the most common applications of Artificial Intelligence. From camera applications in smartphones to Facebook’s tag suggestions, the use of face detection in applications is increasing every single day.

Face detection is the ability of a computer program to identify and locate human faces in a digital image.

With the increasing demand for face detection feature in applications, everyone is looking to use face detection in their application so that they are not left behind in the race.

In this post, I will teach you how to build a face detection program for yourself in less than 3 minutes.You will need to install the following python libraries if it is not already installed:


Here is the code to import the required python libraries, read an image from storage and display it.

# import libraries
import cv2
import matplotlib.pyplot as plt
import cvlib as cvimage_path = 'couple-4445670_640.jpg'
im = cv2.imread(image_path)

Couple Photo (Image by Sonam Prajapati from Pixabay)

The code to detect faces in the loaded image, draw a bounding box around the detected faces and display the final image with detected faces is as follows.

faces, confidences = cv.detect_face(im)# loop through detected faces and add bounding box
for face in faces:    (startX,startY) = face[0],face[1]
    (endX,endY) = face[2],face[3]    # draw rectangle over face
    cv2.rectangle(im, (startX,startY), (endX,endY), (0,255,0), 2)# display output        

Result of Face Detection on couple image

You have your face detection program ready. It is that simple!

To know more about cvlib library, you can visit the link

Thanks for reading

If you liked this post, share it with all of your programming buddies!

Follow us on Facebook | Twitter

Further reading about Python

Python Tutorial - Python GUI Programming - Python GUI Examples (Tkinter Tutorial)

Python Tutorial: Image processing with Python (Using OpenCV)

A guide to Face Detection in Python

Face Detection using Open-CV

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Top 12 Python Libraries for Machine Learning and Data Science in 2020

Python has been the go-to choice for Machine Learning, Data Science and Artificial Intelligence developers for a long time. Python libraries for modern machine learning models & projects: TensorFlow; Numpy; Scipy; Scikit-learn; Theano; Keras; PyTorch; Pandas; Matplotlib; ...

Machine Learning, Data Science and Deep Learning with Python

Complete hands-on Machine Learning tutorial with Data Science, Tensorflow, Artificial Intelligence, and Neural Networks. Introducing Tensorflow, Using Tensorflow, Introducing Keras, Using Keras, Convolutional Neural Networks (CNNs), Recurrent Neural Networks (RNNs), Learning Deep Learning, Machine Learning with Neural Networks, Deep Learning Tutorial with Python

Learning in Artificial Intelligence - Great Learning

What is Artificial Intelligence (AI)? AI is the ability of a machine to think like human, learn and perform tasks like a human. Know the future of AI, Examples of AI and who provides the course of Artificial Intelligence?