Feature detection (SIFT, SURF, ORB) – OpenCV 3.4 with python 3 Tutorial 25

We’re going to learn in this tutorial how to find features on an image.
We have thre different algorythms that we can use:

  • SIFT
  • SURF
  • ORB

Each one of them as pros and cons, it depends on the type of images some algorithm will detect more features than another.
SIFT and SURF are patented so not free for commercial use, while ORB is free.SIFT and SURF detect more features then ORB, but ORB is faster.

First we import the libraries and load the image:

import cv2
import numpy as np

img = cv2.imread("the_book_thief.jpg", cv2.IMREAD_GRAYSCALE)

We then load one by one the three algorythms.

sift = cv2.xfeatures2d.SIFT_create()
surf = cv2.xfeatures2d.SURF_create()
orb = cv2.ORB_create(nfeatures=1500)

We find the keypoints and descriptors of each spefic algorythm.
A keypoint is the position where the feature has been detected, while the descriptor is an array containing numbers to describe that feature.

When the descriptors are similar, it means that also the feature is similar. You can see this tutorial to understand more about feature matching.

keypoints_sift, descriptors = sift.detectAndCompute(img, None)
keypoints_surf, descriptors = surf.detectAndCompute(img, None)
keypoints_orb, descriptors = orb.detectAndCompute(img, None)

We finally draw the keypoints on the image. In this case we are drawing only the keypoints detected from the orb algorythm.

img = cv2.drawKeypoints(img, keypoints, None)

cv2.imshow("Image", img)


Learn to build Computer Vision Software easily and efficiently.

This is a FREE Workshop where I'm going to break down the 4 steps that are necessary to build software to detect and track any object.

Sign UP for FREE