The Wayback Machine - https://web.archive.org/web/20240708035846/https://www.geeksforgeeks.org/feature-matching-using-orb-algorithm-in-python-opencv/
Open In App

Feature matching using ORB algorithm in Python-OpenCV

Last Updated : 04 Jun, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

ORB is a fusion of FAST keypoint detector and BRIEF descriptor with some added features to improve the performance. FAST is Features from Accelerated Segment Test used to detect features from the provided image. It also uses a pyramid to produce multiscale-features. Now it doesn’t compute the orientation and descriptors for the features, so this is where BRIEF comes in the role.

ORB uses BRIEF descriptors but as the BRIEF performs poorly with rotation. So what ORB does is to rotate the BRIEF according to the orientation of keypoints. Using the orientation of the patch, its rotation matrix is found and rotates the BRIEF to get the rotated version. ORB is an efficient alternative to SIFT or SURF algorithms used for feature extraction, in computation cost, matching performance, and mainly the patents. SIFT and SURF are patented and you are supposed to pay them for its use. But ORB is not patented. 

In this tutorial, we are going to learn how to find the features in an image and match them with the other images in a continuous Video.

Algorithm

  • Take the query image and convert it to grayscale. 
  • Now Initialize the ORB detector and detect the keypoints in query image and scene. 
  • Compute the descriptors belonging to both the images. 
  • Match the keypoints using Brute Force Matcher. 
  • Show the matched images. 

Below is the implementation.

Input image:  

Python3
import numpy as np
import cv2
 
    
# Read the query image as query_img
# and train image This query image
# is what you need to find in train image
# Save it in the same directory
# with the name image.jpg  
query_img = cv2.imread('query.jpg')
train_img = cv2.imread('train.jpg')
 
# Convert it to grayscale
query_img_bw = cv2.cvtColor(query_img,cv2.COLOR_BGR2GRAY)
train_img_bw = cv2.cvtColor(train_img, cv2.COLOR_BGR2GRAY)
 
# Initialize the ORB detector algorithm
orb = cv2.ORB_create()
 
# Now detect the keypoints and compute
# the descriptors for the query image
# and train image
queryKeypoints, queryDescriptors = orb.detectAndCompute(query_img_bw,None)
trainKeypoints, trainDescriptors = orb.detectAndCompute(train_img_bw,None)

# Initialize the Matcher for matching
# the keypoints and then match the
# keypoints
matcher = cv2.BFMatcher()
matches = matcher.match(queryDescriptors,trainDescriptors)
 
# draw the matches to the final image
# containing both the images the drawMatches()
# function takes both images and keypoints
# and outputs the matched query image with
# its train image
final_img = cv2.drawMatches(query_img, queryKeypoints, 
train_img, trainKeypoints, matches[:20],None)
 
final_img = cv2.resize(final_img, (1000,650))

# Show the final image
cv2.imshow("Matches", final_img)
cv2.waitKey(3000)

Output: 

Screenshot-from-2020-04-21-02-00-06-copy-2



 


Previous Article
Next Article

Similar Reads

Feature Matching using Brute Force in OpenCV
In this article, we will do feature matching using Brute Force in Python by using OpenCV library. Prerequisites: OpenCV OpenCV is a python library which is used to solve the computer vision problems. OpenCV is an open source Computer Vision library. So computer vision is a way of teaching intelligence to machine and making them see things just like
13 min read
Feature detection and matching with OpenCV-Python
In this article, we are going to see about feature detection in computer vision with OpenCV in Python. Feature detection is the process of checking the important features of the image in this case features of the image can be edges, corners, ridges, and blobs in the images. In OpenCV, there are a number of methods to detect the features of the imag
5 min read
Feature Matching in OpenCV
OpenCV feature matching is a super cool technology in computer vision that's changing how machines understand the visual world. It's super important in things like image search, object recognition, image stitching, and making pictures look better. If you want to level up your image analysis, classification, and autonomous navigation skills, masteri
8 min read
Template matching using OpenCV in Python
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
6 min read
Feature extraction and image classification using OpenCV
This article is your ultimate guide to becoming a pro at image feature extraction and classification using OpenCV and Python. We'll kick things off with an overview of how OpenCV plays a role in feature extraction, and we'll go through the setup process for the OpenCV environment. You'll get to learn all about different feature extraction technique
11 min read
Histogram matching with OpenCV, scikit-image, and Python
Histogram matching is used for normalizing the representation of images, it can be used for feature matching, especially when the pictures are from diverse sources or under varied conditions (depending on the light, etc). each image has a number of channels, each channel is matched individually. Histogram matching is possible only if the number of
3 min read
Multi-template matching with OpenCV
In this tutorial, we are going to see how to perform Multi-template matching with OpenCV. We'll walk you through the entire process of multi-template matching using OpenCV. For this tutorial, you'll need a basic understanding of computer vision with OpenCV and have all the dependencies installed on your working environment. What is template matchin
5 min read
Automatic Document Scanner using OpenCV (OpenCV Document Scanner)
An automatic document scanner using OpenCV is a computer vision application that automatically detects and extracts documents from images. This type of scanner can be useful in various scenarios, such as digitizing paper documents, processing scanned documents, or automating document recognition tasks. In this article, we will see how we can build
6 min read
Transition from OpenCV 2 to OpenCV 3.x
OpenCV is one of the most popular and most used Computer vision libraries. It contains tools to carry out image and video processing. When OpenCV 3..4.1 is an improved version of OpenCV 2.4 as it introduced new algorithms and features. Although some of the existing modules were rewritten and moved to sub-modules. In this articles, I will focus on t
2 min read
Top Books for Learning OpenCV: Computer Vision with OpenCV Library
OpenCV or Open Source Computer Vision Library, is an open-source computer vision and machine learning software library. It's extensively used for real-time computer vision tasks such as object detection, face recognition, image processing, etc. Whether you're a beginner or an experienced developer looking to deepen your understanding of OpenCV, her
5 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg