Experiment No 6
Experiment No 6
Experiment No 6
Theory:
Conceptualizing Haar Cascades:
Haar cascades are a machine learning-based object detection method used to identify
objects in images or video. They were introduced by Viola and Jones in their 2001
paper. The fundamental idea behind Haar cascades is to use a series of progressively
more complex classifiers to quickly eliminate areas in an image that are unlikely to
contain the target object, thus reducing the computational load.
Adaboost: Haar cascades use the Adaboost algorithm to select and weight a subset
of Haar-like features. Adaboost combines weak classifiers (the Haar-like features)
into a strong classifier.
To perform face detection on a still image using OpenCV, you typically follow these
steps:
• Load the Image: Read the still image from a file or capture it using a camera.
• Load the Haar Cascade Classifier: Load the pre-trained Haar cascade classifier
for face detection using the cv2.CascadeClassifier function.
• Draw Rectangles: Iterate through the detected faces and draw rectangles
around them on the original image.
• Display the Result: Display or save the image with the detected faces marked.
Introduction
Discover object detection with the Haar Cascade algorithm using OpenCV. Learn
how to employ this classic method for detecting objects in images and videos.
Explore the underlying principles, step-by-step implementation, and real-world
applications. From facial recognition to vehicle detection, grasp the essence of
Haar Cascade and OpenCV’s role in revolutionizing computer vision. Whether
you’re a novice or an expert, this article will equip you with the skills to harness the
potential of object detection in your projects.
Identifying a custom object in an image is known as object detection. This task can
be done using several techniques, but we will use the haar cascade, the simplest
method to perform object detection in this article.
What is Haar Cascade Algorithm?
Haar cascade is an algorithm that can detect objects in images, irrespective of their
scale in image and location.
This algorithm is not so complex and can run in real-time. We can train a
haarcascade detector to detect various objects like cars, bikes, buildings, fruits, etc.
Haar cascade uses the cascading window, and it tries to compute features in every
window and classify whether it could be an object.
Haar cascade works as a classifier. It classifies positive data points → that are part
of our detected object and negative data points → that don’t contain our object.Haar
cascades are fast and can work well in real-time.Haar cascade is not as accurate as
modern object detection techniques are.Haar cascade has a downside. It predicts
many false positives.Simple to implement, less computing power required.
Code:
import cv2
from google.colab.patches import cv2_imshow
# Convert the image to grayscale (Haar cascades work on grayscale images) gray =
cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
Output:
Conclusion:
Loading the image, importing the necessary libraries, loading the pre-trained
face detection cascade, applying the cascade to the image to detect faces,
drawing rectangles around the detected faces, and finally displaying or saving
the output image are the key steps in this process.
This example lays the groundwork for more advanced computer vision tasks
like facial recognition, emotion detection, and others.