You are on page 1of 9

@ml.

india

FACE DETECTION

ith
w
WEBCAM
using OpenCV and
Haar Cascade
Classifier!

Hit to support! 1 of 9
@ml.india Machine Learning India

What is OpenCV?
OpenCV is an open source, cross-platform library of
programming functions mainly aimed at real-time
computer vision. The library has more than 2500
optimized algorithms, which includes an exhaustive
@ML.INDIA
set of both classic and state-of-the-art computer
vision and machine learning methods.

The installation:
pip install opencv-python

Hit to support! 2 of 9
@ml.india Machine Learning India

What are Haar Cascades?


Haar Cascade classifiers are an effective way for object
(face in our case) detection. This method was proposed
by Paul Viola and Michael Jones in their paper Rapid
Object Detection using a Boosted Cascade of Simple
Features. It's a ML-based approach where a lot of +ve
@ML.INDIA
(containing a face) and -ve (not containing a face)
images are used to train the classifier. This classifier is
then used to detect objects (faces) in other images.

Haar-like
features

Hit to support! 3 of 9
@ml.india Machine Learning India

OpenCV already contains many pre-trained classifiers


for face, eyes, smile @ML.INDIA
etc. They're all present as XML files.
Here's the one we will be needing:

haarcascade_frontalface_default.xml

This file can be downloaded from


the OpenCV Github repository.

Hit to support! 4 of 9
@ml.india Machine Learning India

The Implementation:

@ML.INDIA

Hit to support! 5 of 9
@ml.india Machine Learning India

Through your webcam!

The output should look like:

@ML.INDIA

Note:
- Press ESC to shut the webcam-frame window.
- Press Space to capture a PNG.

Hit to support! 6 of 9
@ml.india Machine Learning India

Want to learn the details?


Join our free webinar!
Topic: Face Recognition Using Python
Instructor: Anil Sharma, PhD Scholar, IIIT-Delhi
When: Saturday, July 18, 2020 (7-8PM).
What you will learn: How to code face
detection and face recognition in Python, to
build a smart home surveillance system
using Raspberry-Pi.
Link: https://bit.ly/FaceRecognitionLive (In the
first comment under this post!)

Hit to support! 7 of 9
@ml.india Machine Learning India

Learn more on:


- Face Detection using Haar Cascades by OpenCV.org.
- Face Detection model on Webcam using Python by
Dilan Jayasekara on Medium.
- Haar-like feature on Wikipedia.

Important note:
The links to these resources will be put up on our Telegram
Channel. Channel ID: @machinelearning24x7.

Hit to support! 8 of 9
@ml.india Machine Learning India

Ever used Haar-Cascades?


Let us know in the comments! If you like our
content and find it valuable, do give us a follow!
Your love and support inspires us to keep
delivering the best we can!
Comment.

Share.
Like.

9 of 9

You might also like