ORB (Oriented FAST and Rotated BRIEF) is a feature detection and description algorithm used to identify and match keypoints between images. It combines the FAST keypoint detector with the BRIEF descriptor and introduces orientation compensation to achieve rotation invariance.
- Uses binary descriptors, resulting in low memory usage and fast matching.
- Suitable for resource-constrained systems such as mobile, embedded, and real-time applications.
Working
- FAST Keypoint Detection: Detects corner-like keypoints in the image using the FAST algorithm.
- Keypoint Selection: Selects the most significant keypoints based on their corner strength.
- Orientation Assignment: Assigns an orientation to each keypoint using intensity moments for rotation invariance.
- BRIEF Descriptor Generation: Creates binary descriptors that represent the local image region around each keypoint.
- Rotated BRIEF (rBRIEF): Rotates the BRIEF descriptors according to the assigned keypoint orientation.
- Feature Matching: Matches keypoints between images using Hamming distance on the binary descriptors.
Implementation
Let's consider two images of the same object. In this implementation, we will use ORB with OpenCV to detect keypoints, compute descriptors, and match features between the images. You may use this sample image.
Step 1: Installing required libraries
Before we start, make sure OpenCV is installed. If not, install it using the following command:
!pip install opencv-python opencv-python-headless
Step 2: Importing Libraries
Importing OpenCV, Numpy and Matplotlib libraries for the implementation.
import numpy as np
import cv2
import matplotlib.pyplot as plt
from google.colab.patches import cv2_imshow
Step 3: Loading the Images
Loading the query and training images using cv2.imread() and convert them to grayscale since ORB operates on single-channel images.
query_img = cv2.imread('/content/sports-car test.webp')
train_img = cv2.imread('/content/sports-car train.webp')
query_img_bw = cv2.cvtColor(query_img, cv2.COLOR_BGR2GRAY)
train_img_bw = cv2.cvtColor(train_img, cv2.COLOR_BGR2GRAY)
Step 4: Detecting Keypoints and Finding Descriptors
Using the ORB detector to identify keypoints in both images and compute their corresponding descriptors. The keypoints represent distinctive image regions, while the descriptors encode their local appearance for feature matching.
orb = cv2.ORB_create()
queryKeypoints, queryDescriptors = orb.detectAndCompute(query_img_bw, None)
trainKeypoints, trainDescriptors = orb.detectAndCompute(train_img_bw, None)
Step 5: Matching the Descriptors
We use a Brute-Force Matcher to compare the descriptors from both images and find the best matching keypoints based on descriptor similarity.
matcher = cv2.BFMatcher()
matches = matcher.match(queryDescriptors, trainDescriptors)
Step 6: Visualizing the Matches
Finally, we visualize the matches by drawing lines between the matched keypoints. The output image is resized for improved visibility and displayed using Matplotlib.
final_img = cv2.drawMatches(query_img, queryKeypoints,
train_img, trainKeypoints, matches[:20], None)
final_img = cv2.resize(final_img, (1000, 650))
plt.figure(figsize=(10, 6))
plt.imshow(cv2.cvtColor(final_img, cv2.COLOR_BGR2RGB))
plt.title("Feature Matches")
plt.axis('off')
plt.show()
Output:

Applications
- Object Recognition: Identifying objects in different images, even if they are rotated or scaled differently.
- Image Stitching: Combining multiple images to form a panorama by matching common features.
- Augmented Reality: Matching real-world scenes to virtual objects by identifying key features in camera feeds.
- 3D Reconstruction: Matching features from different views to construct 3D models.
Advantages
- Faster feature detection and matching than many traditional feature descriptors.
- Uses binary descriptors, resulting in low memory consumption.
- Supports multiscale feature detection through image pyramids.
- Patent-free and freely available for commercial and research use.
Limitations
- May produce fewer reliable keypoints in low-texture or uniform image regions.
- Performance can be affected by image noise and significant illumination changes.
- Generally less robust than SIFT for large scale and viewpoint variations.
- Descriptor matching can become computationally expensive for very large feature sets.