Face Detection App in Just 5 Minutes | OpenCV Project

In this tutorial, I have touched you, how to create a Face Detection App in only 5 Minutes. Its computer vision Artificial Intelligence project and I used OpenCV Python Library and Cascade Classifier.


Face Detection App Project Code

# import OpenCV
import cv2

# Load trained cascade classifier
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

# Read the given image
color_image = cv2.imread('girl.png')

# Convert color image into grayscale
gray_image = cv2.cvtColor(color_image, cv2.COLOR_BGR2GRAY)

# Detect faces ROI
#Syntax: Classifier.detectMultiScale(input image, Scale Factor , Min Neighbors)
faces = face_cascade.detectMultiScale(gray_image, 1.1, 5) 

# Draw rectangle around the faces
for (x, y, w, h) in faces:
    cv2.rectangle(color_image, (x, y), (x + w, y + h), (0, 0, 255), 4)
# Show image
cv2.imshow('Image', color_image)

#wait to close window

#close all windows

Leave a Reply