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 https://towardsdatascience.com

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:

opencv-python cvlib

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) plt.imshow(im)

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
plt.imshow(im)

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

machine-learning python artificial-intelligence data-science

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.