Implementations

Fast Feature Detector

import cv2

img = cv2.imread('images/aeroplane.jpg', 0)

detector = cv2.FastFeatureDetector_create(5)

kp = detector.detect(img, None)

img2 = cv2.drawKeypoints(img, kp, None, flags=0)


cv2.imshow('Corners', img2)
cv2.waitKey(0)

Harris Corner Detector

import cv2
import numpy as np

#Detector parameters
block_size = 2
k_size = 7
k = 0.04


img = cv2.imread('images/grains.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)

harris = cv2.cornerHarris(gray, block_size, k_size, k)

img[harris > 0.01 * harris.max()] = [255, 0, 0]

cv2.imshow('Harris', img)
cv2.waitKey(0)

SHI-Thomas Corner Detector

import cv2
import numpy as np

img = cv2.imread('images/aeroplane.jpg')

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)

corners = cv2.goodFeaturesToTrack(gray, 25, 0.01, 10)
corners = np.int0(corners)

for i in  corners:
        x, y = i.ravel()
        cv2.circle(img, (x, y), 2, (255, 0, 255), 2)

cv2.imshow('Shi-Thomas corner detection', img)
cv2.waitKey(0)

ORB

import cv2
import numpy as np

#ORB = FAST detector and BRIEF descriptor

img = cv2.imread('images/aeroplane.jpg')

ORB = cv2.ORB_create(50)
keyP, descriptor = ORB.detectAndCompute(img, None)

img2 = cv2.drawKeypoints(img, keyP, None, (255, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.imshow('Result', img2)
cv2.waitKey(0)

Last updated