live face detection app

Build Your Own Live Face Detection App in 8 Minutes | OpenCV

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

live face detection app

Live Face Detection App Project Code

#import opencv
import cv2

# Load the Cascade Classifier
face_cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")

#startt  web cam
cap = cv2.VideoCapture('videos/school_girl.mp4')

while True:
    
    #read image from webcam
    respose, color_img = cap.read()
    
    # Convert to grayscale
    gray_img = cv2.cvtColor(color_img, cv2.COLOR_BGR2GRAY)
    
    # Detect the faces
    faces = face_cascade.detectMultiScale(gray_img, 1.4, 7)
    
    #display rectrangle
    for (x, y, w, h) in faces:
        cv2.rectangle(color_img, (x, y), (x+w, y+h), (0, 0, 255), 3)
    
    # display image
    cv2.imshow('img', color_img)
    
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Release the VideoCapture object
cap.release()
cv2.destroyAllWindows()

Leave a Reply