![]() |
VOOZH | about |
Haar Cascade classifiers are a machine learning-based method for object detection. They use a set of positive and negative images to train a classifier, which is then used to detect objects in new images.
In this article we will learn how to perform detection using Haar Cascades.
We will go through the step-by-step procedure to implement object detection using Haar Cascades.
Here, we will use Numpy, OpenCV and Matplotlib.
Next we will load the pre-trained Haar Cascade classifiers for detecting faces and eyes. You can download these classifier from this link.
Now weβll create a function adjusted_detect_face() to detect faces in an image. This function uses the face cascade classifier to identify face rectangles and draws rectangles around the detected faces.
Similarly we create a function detect_eyes() to detect eyes using the eye cascade classifier.
Now letβs load an image and apply both face and eye detection on it. The image which we are using can be downloaded from this link.
Output:
After running the code you will see three images Face Detection, Eyes Detection and Face and Eyes Detection. These images will also be saved as face.jpg, eyes.jpg and face+eyes.jpg respectively.
Face Detection:
Output:
Eyes Detection:
Output:
Face and Eyes Detection:
Output:
In this article, we explored Haar Cascades for object detection. By using pre-trained XML files we can detect different objects with minimal setup. Moreover the flexibility of Haar Cascades allows us to create custom XML files tailored to detect specific objects offering a wide range of computer vision applications.