Feature detection identifies key points or distinctive patterns in an image. These features are useful in object recognition, image stitching, tracking, and 3D reconstruction. OpenCV provides popular algorithms like Harris Corner Detector, SIFT, and ORB.
Detects corners (points where edges meet). Suitable for simple corner detection tasks.
import cv2
import numpy as np
img = cv2.imread("chessboard.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
harris = cv2.cornerHarris(gray, 2, 3, 0.04)
img[harris > 0.01 * harris.max()] = [0, 0, 255]
cv2.imshow("Harris Corners", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
SIFT detects and describes scale-invariant features, making it robust to changes in size, rotation, and illumination.
sift = cv2.SIFT_create()
keypoints, descriptors = sift.detectAndCompute(gray, None)
img_sift = cv2.drawKeypoints(img, keypoints, None, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.imshow("SIFT Features", img_sift)
cv2.waitKey(0)
cv2.destroyAllWindows()
ORB is a fast and efficient alternative to SIFT, suitable for real-time applications.
orb = cv2.ORB_create()
keypoints, descriptors = orb.detectAndCompute(gray, None)
img_orb = cv2.drawKeypoints(img, keypoints, None, color=(0,255,0), flags=0)
cv2.imshow("ORB Features", img_orb)
cv2.waitKey(0)
cv2.destroyAllWindows()
✅ In this lesson, you learned about Harris Corner, SIFT, and ORB for feature detection in OpenCV.
These algorithms are widely used in object recognition, panorama creation, augmented reality, and real-time tracking.
👉 With this, we complete Module 3: Image Segmentation & Feature Detection. Next, we’ll test your knowledge with Quiz 3 🎯
