Module 4: Feature Extraction and Matching

1. Learning Objectives

2. Key Concepts

3. Keypoint Detectors

4. Descriptors

5. Feature Matching Techniques

6. Hands-On Lab

Use OpenCV to detect keypoints and match features between two uploaded images.

import cv2
import numpy as np
from google.colab.patches import cv2_imshow
from google.colab import files

# Upload two images
uploaded = files.upload()
img1 = cv2.imread(list(uploaded.keys())[0], 0)  # Grayscale
uploaded = files.upload()
img2 = cv2.imread(list(uploaded.keys())[0], 0)

# Detect ORB keypoints and descriptors
orb = cv2.ORB_create()
kp1, des1 = orb.detectAndCompute(img1, None)
kp2, des2 = orb.detectAndCompute(img2, None)

# Match descriptors using BFMatcher
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = bf.match(des1, des2)
matches = sorted(matches, key=lambda x: x.distance)

# Draw top 20 matches
matched_img = cv2.drawMatches(img1, kp1, img2, kp2, matches[:20], None, flags=2)
cv2_imshow(matched_img)

7. Real-World Applications

8. Assignment

Objective: Practice keypoint detection and feature matching with real-world images.

Due: End of Week 4