Hi learners!! We always come across the problem face detection in machine learning and we always jut think that how we can create a face detection algorithm in the easiest and fastest way. Well here is the answer! we will use OpenCV library of python for detecting faces in the live video being fed using your webcam. For initial level we are using this library but next time we will be creating our own model from scratch and will train it and then test it in real time!!
OpenCV is a library of python which supports a built in model for detecting faces in an image using Haar Cascades. We can use OpenCV for extracting frames from a video then we will apply Haar Cascade onto those frames and will create square on the face being present in image.
NOTE: Before moving onto the code you will be needed to download the “haarcascade_frontalface_default.xml” for running this face detection algorithm. You can find it here. This file basically contains weights for detecting faces
#importing OpenCV and Time library
#Reading data from the CSV file we downloaded
#Capturing Video from primary webcam, you can change number from 0 to any Integer
## for other webcams if you have many of them
#Reading frame from the live video feed
#Converting frame into grayscale for better efficiency
#Using Haar Cascade for detecting faces in an image
#Creating the rectangle around face
#Displaying the captured frame in a window
#Applied 0.5 seconds delay such that a new frame will only be read every 0.5 seconds
#This decreases load on machine, because in general webcam captures 15 to 25 frames per second
Input – Output
The above algorithm was for starters!! In next tutorial we will be creating a face detection algorithm from scratch, then we will train it and use it!
Stay tuned for more learning!!
PLEASE WRITE YOUR COMMENTS.