0% found this document useful (0 votes)
7 views23 pages

Module 3

Module 3 covers object detection techniques, including the differences between object detection and recognition, challenges faced in real-world scenarios, and methods for contour detection using OpenCV. It discusses template matching for logo detection, its applications, advantages, and limitations, as well as the use of bounding boxes for labeling and tracking objects in images. The module emphasizes the importance of consistent labeling and tight bounding boxes for effective machine learning model training.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views23 pages

Module 3

Module 3 covers object detection techniques, including the differences between object detection and recognition, challenges faced in real-world scenarios, and methods for contour detection using OpenCV. It discusses template matching for logo detection, its applications, advantages, and limitations, as well as the use of bounding boxes for labeling and tracking objects in images. The module emphasizes the importance of consistent labeling and tight bounding boxes for effective machine learning model training.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Module 3:

Object Detection:

Object Detection Vs Object Recognition

1
Challenges in Object Detection:

2
How Lighting A?ects Real-world Object Detection?

3
How Occlusion and Scale A?ect Real-World Object Detection?

4
Real-world examples:

1. Vehicles far away in tra?ic scenes


2. Drones or birds at high altitude
3. Surveillance cameras with wide fields of view
Contour Detection & Shape Analysis

5
Steps for Detecting and Drawing Contours in OpenCV

1) Read the Image and convert it to Grayscale Format

Converting the image to a single-channel grayscale image is important for thresholding,


which in turn is necessary for the contour detection algorithm to work properly.

2) Apply Binary Thresholding

While finding contours, first always apply binary thresholding or Canny edge detection
to the grayscale image. This converts the image to black and white. Thresholding sets
the object's border in the image to completely white, with all pixels having the same
intensity. The algorithm can now detect the borders of the objects from these white
pixels. The black pixels, having value 0, are perceived as background pixels and ignored.

3) Find the Contours

Use the findContours() function to detect the contours in the image.

Drawing Contours using CHAIN_APPROX_NONE

Start with the findContours() function.

It has three required arguments

6
1) image: The binary input image obtained in the previous step.
2) mode: This is the contour-retrieval mode. We provided this as RETR_TREE,
which means the algorithm will retrieve all possible contours from the binary
image. (type of contours)
3) method: CHAIN_APPROX_NONE This defines the contour-approximation
method.

4) Draw Contours on the Original RGB Image

Once contours have been identified, use the drawContours() function to overlay the
contours on the original RGB image.

• Use the drawContours() function to overlay the contours on the RGB


image.
• This function has four required and several optional arguments.
• The first four arguments below are required.

7
Suzuki-Abe Contour Tracing Algorithm

8
9
10
Contour Approximation

The function [Link]() approximates a contour shape to another shape with


less number of vertices.

How to approximate a contour shape in an image using OpenCV Python?

11
Quantitative Shape Analysis

12
In quantitative shape analysis, once an object is segmented and its contour is
extracted, we compute numerical features that describe the shape. The most basic and
important ones are to calculate area and perimeter.

13
Shape Classification Using Contour Properties

Shape classification using contour properties is a classic (and still very solid) computer-

vision approach.

14
Template Matching

Template matching is a technique for finding areas of an image that are similar to a
patch (template). A patch is a small image with certain features. The goal of template
matching is to find the patch/template in an image. To find it, the user has to give two
input images: Source Image (S) - The image to find the template in, and Template Image
(T) - The image that is to be found in the source image.

• It is basically a method for searching and finding the location of a template


image in a larger image.

• The idea here is to find identical regions of an image that match a template we
provide, giving a threshold

The threshold depends on the accuracy with which we want to detect the template in
the source image.

For instance, if we are applying face recognition and we want to detect the eyes of a
person, we can provide a random image of an eye as the template and search for the
source (the face of a person).

15
In this case, since "eyes" show a large number of variations from person to person, even
if we set the threshold as 50%(0.5), the eye will be detected.

In cases where almost identical templates are to be searched, the threshold should be
set high.(t>=0.8)

How does Template Matching Work?

• The template image simply slides over the input image (as in 2D convolution)
• The template and patch of input image under the template image are compared.
• The result obtained is compared with the threshold.
• If the result is greater than the threshold, the portion will be marked as detected.
• In the function
[Link](img_gray,template,cv2.TM_CCOEFF_NORMED) the first
parameter is the main image, the second parameter is the template to be
matched and the third parameter is the method used for matching.

Limitations of Template Matching:


• Pattern occurrences have to preserve the orientation of the reference
pattern image(template)
• As a result, it does not work for rotated or scaled versions of the template,
as a change in shape/size/shear, etc. of the object with respect to the
template will give a false match.
• The method is ine?icient when calculating the pattern correlation image
for medium to large images, as the process is time-consuming.

Applications in Logo Detection


Logo detection is the task of identifying and locating a brand logo within an image or video.
In computer vision, one of the simplest and most widely used classical approaches for logo
detection is template matching. This method compares a predefined logo template with
regions of a target image to determine similarity.

Template matching is especially effective when the logo has a fixed appearance, limited scale
variation, and minimal rotation.

16
Template matching is a sliding-window technique where a small image (the template) is
moved over a larger image (the search image). At each position, a similarity measure is
computed between the template and the corresponding image region.
OpenCV implements this process using the function:
[Link]()
The output is a similarity map, indicating how well the template matches at each location.
3 Template Matching Methods
OpenCV provides several matching metrics. For logo detection, the most commonly used
method is:
TM_CCOEFF_NORMED
• Computes the normalized correlation coefficient
• Output range: −1 to 1
• Higher values indicate stronger similarity
• Less sensitive to illumination changes
• This normalization makes it particularly suitable for real-world logo detection.
Workflow for Logo Detection
Step 1: Preprocessing
Convert images to grayscale
Resize the logo template if necessary
Optionally apply edge detection to reduce lighting effects
Step 2: Matching
Slide the template across the input image
Compute similarity at each location
Step 3: Thresholding
Select locations where similarity exceeds a predefined threshold
These locations are considered logo detections
Step 4: Localization
Draw bounding boxes around detected logo regions
Applications
• Template matching for logo detection is used in:
• Brand monitoring in TV broadcasts and social media
• Copyright and watermark detection
• User interface automation
• Product authentication
Advantages
• Simple to implement
• Computationally efficient
• No training data required
• Works well for fixed-size logos
Limitations
o Sensitive to scale and rotation changes
o Performance degrades in cluttered backgrounds
o Not suitable for detecting multiple logo types at once

17
UI Element Detection
[Start]

[Capture UI Screenshot]

[Load Template Image of UI Element]

[Convert both images to grayscale]

[Slide template over screenshot & calculate similarity]

[Check similarity ≥ threshold?] → Yes → [Mark as Detected]
No → [Continue Searching]

[Return coordinates of detected UI element]

[End]

Bounding Boxes and Labels

18
Bounding boxes also known as bounding volume or region are rectangular region
labels used for computer vision (CV) tasks.
In supervised machine learning (ML), an object detection model uses bounding
box labels. This helps it learn about what is in an image.
The bounding box marks objects or features that the values. This can be a
person, tra?ic sign, vehicle, or almost anything else.
The model learns about the content inside the bounding box to predict the
presence of similar objects when exposed to new unseen data.

Bounding volumes are defined by two points, usually the top-left and bottom-right corners of
the box. People often use these simple rectangular labels for object detection and localization
tasks. They provide an easy way to show the position and size of objects in an image.
Uses of Bounding Boxes

Bounding boxes are used to label data for computer vision tasks, including:

Object Detection: Bounding Volume identify and localize objects within an image, such as
detecting pedestrians, cars, and animals. They represent object locations and are compatible
with many machine-learning algorithms. Object detection models like YOLO learn from a
labeled dataset to predict bounding boxes on new, unseen data.

Object Tracking: Similarly, in video models, bounding volumes are utilized to track the
movement and position of objects over time, enabling applications like video surveillance,
sports analytics, and autonomous vehicles, among others.

Bounding boxes

It’s worth highlighting that object detection differs from other CV tasks like segmentation.

Here, the goal is to identify objects within the image.

1. Consistent Labeling

It’s crucial to ensure that the same object class is consistently labeled with the same name
across all images in the dataset.

Consistency is essential for training models that can accurately recognize objects.

2: Tight Boxes

Labelers must label bounding boxes tightly around the object, ensuring that the box’s edges
touch the object’s boundaries without cutting off any part of it.

Tight bounding boxes provide better localization information for learning algorithms.

Drawing Rectangles around Detected Objects

When detecting objects in an image, we usually want to visualize where the object is located.

A rectangle (bounding box) shows the position and size of the detected object.

19
Coordinates are usually the top-left corner (x, y) and the width w and height h of the object.

Basic Steps

Step 1: Detect Object

Use any detection method (e.g., template matching, feature detection, ML model).

Obtain coordinates of detected object(s).

For example, after template matching you might have:

Step 2: Draw Rectangle

In OpenCV, use the [Link]() function:

Adding Labels & Confidence Scores

Why Add Labels & Confidence Scores

Labels tell what the detected object is (e.g., “Button”, “Car”).

Confidence scores tell how certain the model is about the detection (usually 0–1 or 0–100%).

Together, they improve interpretability and visualisation.

20
Comparison of Object Detection Approaches

1. Template / Pattern Matching

21
Classical Template Matching Vs ML Based Detection

22
23

You might also like