- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to implement ORB feature detectors in OpenCV Python?
ORB (Oriented FAST and Rotated BRIEF) is a fusion of FAST keypoint detector and BRIEF descriptors with many changes to enhance the performance. To implement ORB feature detector and descriptors, you could follow the steps given below
Import the required libraries OpenCV and NumPy. Make sure you have already installed them.
Read the input image using cv2.imread() method. Specify the full path of the image. Convert the input image to grayscale image using cv2.cvtColor() method.
Initiate the ORB object with default values using orb=cv2.ORB_create().
Detect and compute the feature keypoints 'kp' and descriptor 'des' in the grayscale image. Use orb.detectAndCompute(). It returns keypoints 'kp' and descriptors 'des'.
Draw the detected feature keypoint kp on the image using cv2.drawKeypoints() function. To draw rich feature keypoints you can pass flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS as a parameter.
Display the image with drawn feature keypoints on it.
Let's look at some examples to detect and draw keypoints in the input image using the ORB feature detector.
Input Image
We will use the following image as the input file in the examples below.
Example
In this Python program, we detect and compute keypoints and descriptors in the input image using ORB feature detector. We also draw the keypoints on the image and display it.
# import required libraries import cv2 # read input image img = cv2.imread('house.jpg') # convert the image to grayscale gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Initiate ORB object with default values orb = cv2.ORB_create(nfeatures=2000) # detect and compute the keypoints on image (grayscale) kp = orb.detect(gray, None) kp, des = orb.compute(gray, kp) # draw keypoints in image img1 = cv2.drawKeypoints(gray, kp, None, (0,0,255), flags=0) # display the image with keypoints drawn on it cv2.imshow("ORB Keypoints", img1) cv2.waitKey(0) cv2.destroyAllWindows()
Output
When we execute the above program, it will produce the following output window −
The keypoints are shown in red color.
Example
In this Python program too, we detect and compute keypoints and descriptors in the input image using ORB feature detector. We also draw the keypoints on the image and display it.
We use the flag cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS to draw keypoints.
# import required libraries import cv2 # read input image img = cv2.imread('house.jpg') # convert the image to grayscale gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Initiate ORB object with default values orb = cv2.ORB_create(nfeatures=50) # detect and compute the keypoints on image (grayscale) kp, des = orb.detectAndCompute(gray, None) # draw keypoints in image img1 = cv2.drawKeypoints(img, kp, None,(0,0,255), flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) # display the image with keypoints drawn on it cv2.imshow("ORB Keypoints", img1) cv2.waitKey(0) cv2.destroyAllWindows()
Output
When we execute the above program, it will produce the following output window −
In the above output image, the keypoints are drawn with their size and orientation. We find and draw 50 feature keypoints.
- Related Articles
- How to implement FLANN based feature matching in OpenCV Python?
- How to detect and draw FAST feature points in OpenCV Python?
- How to implement probabilistic Hough Transform in OpenCV Python?
- OpenCV Python – Matching the key points of two images using ORB and BFmatcher
- OpenCV Python – Implementing feature matching between two images using SIFT
- How to implement blur (averaging) in OpenCV using Java?
- How to implement Gaussian blur in OpenCV using Java?
- How to implement Bilateral blur in OpenCV using Java?
- How to implement Median blur in OpenCV using Java?
- How to install OpenCV in Python?
- Python - How and where to apply Feature Scaling?
- How can Tensorflow be used to define feature columns in Python?
- How to read an image in Python OpenCV?
- How to match image shapes in OpenCV Python?
- How to Compute Image Moments in OpenCV Python?
