Updated April 19, 2023
Introduction to OpenCV ORB
The following article provides an outline for OpenCV ORB. The algorithm used for the detection of features from the given image along with the orientation and descriptors for the image is called the ORB algorithm and it is a combination of the FAST keypoint detector and BRIEF descriptor where the rotation performed by the BRIEF is rotated by the ORB as per the orientation of the key point to find the rotation matrix and in terms of computation cost, performance, extraction of features and patents, ORB algorithm is the best alternative when compared to SIFT and SURF algorithms and we make use of ORB() function to implement the ORB algorithm by creating an object of ORB.
Syntax to define ORB() function in OpenCV:
ORB_object = cv.ORB_create()
keypoints = ORB_object.detect(input_image)
keypoints, descriptors = ORB_object.compute(input_image, keypoints)
Where,
- ORB_create()is used to create an ORB object ORB_object.
- ORB_object.detect() function is used to detect the key points in the given image input_image.
- ORB_object.compute() function is used to compute the descriptors for the given input image input_image.
Working of ORB Algorithm Using ORB() in OpenCV
- The ORB algorithm can be applied to an image to detect the features from the image along with orientations and descriptors.
- The ORB algorithm can be implemented using a function called ORB() function.
- The implementation of the ORB algorithm works by creating an object of ORB() function.
- Then we make use of a function called ORB_object.detect() function to detect the key points from a given image.
- Then we make use of a function called ORB_object.compute() function to compute the descriptors for a given image.
- Then the image with computed key points drawn on the image is returned as an output.
Examples of OpenCV ORB
Given below are the examples of OpenCV ORB:
Example #1
OpenCV program in python to implement ORB algorithm using ORB() function to detect the key points of a given image and draw the key points on the image and display the resulting image as the output on the screen.
Code:
#importing the required module
import cv2 as cv
#reading the image whose key points are to detected using imread() function
imageread = cv.imread('C:/Users/admin/Desktop/Images/logo.png')
#creating an object of ORB() function to detect the key points in the image
ORB_object = cv.ORB_create()
#detecting the key points in the image using ORB_object.detect() function
keypoints = ORB_object.detect(imageread)
#computing the descriptors for the input image using ORB_object.compute() function
keypoints, descriptors = ORB_object.compute(imageread, keypoints)
#using drawKeypoints() function to draw the detected key points on the image
imageresult = cv.drawKeypoints(imageread, keypoints, None, color=(255,0,0), flags=0)
#displaying the resulting image as the output on the screen
cv.imshow('ORB_image', imageresult)
cv.waitKey()
Output:
In the above program, the required module cv2 is imported. Then we are reading the image whose key points are to be detected using imread() function. Then we are creating an object of ORB() function to detect the key points in the image. Then we are detecting the key points in the image using ORB_object.detect() function. Then we are computing the descriptors for the input image using ORB_object.compute() function. Then we are drawing the detected key points on the image using drawKeypoints() function. Then we are displaying the resulting image as the output on the screen. The output is shown in the snapshot above.
Example #2
OpenCV program in python to implement ORB algorithm using ORB() function to detect the key points of a given image and draw the key points on the image and display the resulting image as the output on the screen.
Code:
#importing the required module
import cv2 as cv
#reading the image whose key points are to detected using imread() function
imageread = cv.imread('C:/Users/admin/Desktop/Images/educba.jpg')
#creating an object of ORB() function to detect the key points in the image
ORB_object = cv.ORB_create()
#detecting the key points in the image using ORB_object.detect() function
keypoints = ORB_object.detect(imageread)
#computing the descriptors for the input image using ORB_object.compute() function
keypoints, descriptors = ORB_object.compute(imageread, keypoints)
#using drawKeypoints() function to draw the detected key points on the image
imageresult = cv.drawKeypoints(imageread, keypoints, None, color=(255,0,0), flags=0)
#displaying the resulting image as the output on the screen
cv.imshow('ORB_image', imageresult)
cv.waitKey()
Output:
In the above program, the required module cv2 is imported. Then we are reading the image whose key points are to be detected using imread() function. Then we are creating an object of ORB() function to detect the key points in the image. Then we are detecting the key points in the image using ORB_object.detect() function. Then we are computing the descriptors for the input image using ORB_object.compute() function. Then we are drawing the detected key points on the image using drawKeypoints() function. Then we are displaying the resulting image as the output on the screen. The output is shown in the snapshot above.
Example #3
OpenCV program in python to implement ORB algorithm using ORB() function to detect the key points of a given image and draw the key points on the image and display the resulting image as the output on the screen.
Code:
#importing the required module
import cv2 as cv
#reading the image whose key points are to detected using imread() function
imageread = cv.imread('C:/Users/admin/Desktop/Images/educbalogo.jpg')
#creating an object of ORB() function to detect the key points in the image
ORB_object = cv.ORB_create()
#detecting the key points in the image using ORB_object.detect() function
keypoints = ORB_object.detect(imageread)
#computing the descriptors for the input image using ORB_object.compute() function
keypoints, descriptors = ORB_object.compute(imageread, keypoints)
#using drawKeypoints() function to draw the detected key points on the image
imageresult = cv.drawKeypoints(imageread, keypoints, None, color=(255,0,0), flags=0)
#displaying the resulting image as the output on the screen
cv.imshow('ORB_image', imageresult)
cv.waitKey()
Output:
In the above program, the required module cv2 is imported. Then we are reading the image whose key points are to be detected using imread() function. Then we are creating an object of ORB() function to detect the key points in the image. Then we are detecting the key points in the image using ORB_object.detect() function. Then we are computing the descriptors for the input image using ORB_object.compute() function. Then we are drawing the detected key points on the image using drawKeypoints() function. Then we are displaying the resulting image as the output on the screen. The output is shown in the snapshot above.
Recommended Articles
We hope that this EDUCBA information on “OpenCV ORB” was beneficial to you. You can view EDUCBA’s recommended articles for more information.