Easy feature detection and matching project

MariceMane
4 min readAug 27, 2022

--

object detection, object tracking, and object classification applications.

It is common knowledge that data preprocessing is a required first step before any machine learning machinery can be applied. it is also a crucial step for any data analysis project.

Companies nowadays rely on data to make data-driven decisions to improve their businesses and be more accurate and precise in their choices. they use data collected from various places and in different formats.

Their sources are divided into 2, primary data which is extracted directly from the official sources by performing techniques such as questionnaires, interviews, and surveys.

And secondary data which is data that has already been collected and reused again for some valid purpose.

This collected data is considered raw and can’t be used directly as it contains many errors and missing values and can be subject to incompleteness, inconsistency, or lack of appropriate representation of trends.

Therefore it will be preprocessed, which can be defined as the process which helps in converting all the raw data into useful and usable data. the output needs to be complete, not noisy, and reliable information.

Today, we will focus on one type of data which is an image. Some of the preprocessing techniques for images include transforming Pixel brightness such as converting colored images to grayscale or applying brightness corrections to reduce computation complexity, standardizing images by resizing them to a unified dimension, and applying geometric transformations meaning the spatial transformation of the physical rearrangement of pixels in the image such as rotating, scaling or translating the image.

Sometimes images require more than the usual preprocessing techniques to retrieve useful information from them.

For example, let’s consider this scenario: you are working on a computer vision project. you need to retrieve text from an image that contains an id card.

To apply OpenCV functions you need to precise the coordinates to generate the bounding box of your text.

But each image has the card in a different place. So you can’t have fixed coordinates of the text and you choose not to do it manually for each image.

So what can you do instead?

Feature detection and matching is the answer in this case. it is an important task in many computer vision applications, such as structure-from-motion, image retrieval, object detection, and more. In digital images, the concept of feature in computer vision refers to a piece of information, which represents the characteristics of the image.

Feature detection is the process of checking the important features of the image which can be edges, corners, ridges, and blobs in the images.

Feature matching refers to finding matching features from two similar images based on a search distance algorithm. used to find or derive and transfer attributes from the source to the target image. The feature matching process typically analyzes the topology of the source and target images, detects feature patterns, matches the patterns, and matches the features in the discovered patterns.

I am working with Google Colab for the code part. Let’s start by importing all our libraries :

We will be needing to verify the version of OpenCV and install the right one:

We load our test image and main image. in this example, we are trying to locate the img2 which is the id cord in the test_image.

test image (left), the reference image img2 (right)

We will be using SIFT (Scale Invariant Fourier Transform) which is a detector used in the detection of interest points on an input image. It allows the identification of localized features in images.

Now we will detect the key points and compute the descriptors for the reference image and train the image.

Then we Initialize the Matcher for matching the key points and then match them. the plotted result below shows all the features that are similar with a 75% threshold.

In the final piece of code, we are going to retrieve the image inside the test image

Retrieved image.

To conclude, The above-mentioned technique is used in object detection, object tracking, and object classification applications. it is easy and it fixes various problems.

--

--