Bird
Raised Fist0
Computer Visionml~20 mins

Feature matching between images in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Feature Matching Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Feature Matching

Which of the following best describes the purpose of feature matching between images in computer vision?

ATo find corresponding points between two images to understand their spatial relationship
BTo increase the resolution of an image by adding more pixels
CTo convert a color image into grayscale for easier processing
DTo segment an image into different objects based on color
Attempts:
2 left
💡 Hint

Think about why we want to find points that look similar in two different pictures.

Predict Output
intermediate
2:00remaining
Output of Feature Matching Code

What is the output of the following Python code snippet using OpenCV for feature matching?

Computer Vision
import cv2
img1 = cv2.imread('image1.jpg', 0)
img2 = cv2.imread('image2.jpg', 0)
sift = cv2.SIFT_create()
kp1, des1 = sift.detectAndCompute(img1, None)
kp2, des2 = sift.detectAndCompute(img2, None)
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1, des2, k=2)
good = []
for m, n in matches:
    if m.distance < 0.75 * n.distance:
        good.append(m)
print(len(good))
AA boolean indicating if the images are identical
BA list of keypoints detected in the first image
CA tuple containing descriptors of both images
DAn integer representing the number of good matches found between the two images
Attempts:
2 left
💡 Hint

Look at what is printed at the end of the code.

Model Choice
advanced
1:30remaining
Choosing the Best Feature Detector

You want to match features between two images taken under different lighting conditions and slight rotations. Which feature detector is most suitable?

AHarris Corner Detector
BSIFT (Scale-Invariant Feature Transform)
CCanny Edge Detector
DHistogram of Oriented Gradients (HOG)
Attempts:
2 left
💡 Hint

Consider which detector is robust to scale, rotation, and lighting changes.

Metrics
advanced
1:30remaining
Evaluating Feature Matching Quality

Which metric is commonly used to evaluate the quality of feature matching between two images?

ANumber of inlier matches after applying RANSAC
BMean squared error between pixel intensities
CConfusion matrix of classification labels
DCross-entropy loss of a neural network
Attempts:
2 left
💡 Hint

Think about how to measure how many matches are geometrically consistent.

🔧 Debug
expert
2:00remaining
Debugging Feature Matching Code

Consider this code snippet for feature matching. What error will it raise when run?

Computer Vision
import cv2
img1 = cv2.imread('img1.jpg', 0)
img2 = cv2.imread('img2.jpg', 0)
sift = cv2.SIFT_create()
kp1, des1 = sift.detectAndCompute(img1, None)
kp2, des2 = sift.detectAndCompute(img2, None)
bf = cv2.BFMatcher()
matches = bf.match(des1, des2)
print(matches[0].queryIdx)
AIndexError because matches list is empty
BTypeError because BFMatcher.match expects descriptors as lists
CAttributeError because 'NoneType' object has no attribute 'shape'
DNo error, prints the query index of the first match
Attempts:
2 left
💡 Hint

Check what happens if images are not loaded properly.

Practice

(1/5)
1. What is the main purpose of feature matching between two images?
easy
A. To find similar points or patterns between the images
B. To change the colors of the images
C. To increase the image resolution
D. To crop the images automatically

Solution

  1. Step 1: Understand feature matching concept

    Feature matching is used to find points in two images that look alike, such as corners or edges.
  2. Step 2: Identify the main goal

    The goal is to find these similar points to compare or align images, not to change colors or resolution.
  3. Final Answer:

    To find similar points or patterns between the images -> Option A
  4. Quick Check:

    Feature matching = find similar points [OK]
Hint: Feature matching finds points that look alike in two images [OK]
Common Mistakes:
  • Confusing feature matching with image editing
  • Thinking it changes image size or colors
  • Mixing feature matching with image cropping
2. Which of the following is the correct way to detect keypoints using ORB in OpenCV (Python)?
easy
A. orb = cv2.ORB_create(); keypoints = orb.getKeypoints(image)
B. orb = cv2.ORB(); keypoints = orb.find(image)
C. orb = cv2.ORB_create(); keypoints = orb.detect(image, None)
D. orb = cv2.ORB_create(); keypoints = orb.findKeypoints(image)

Solution

  1. Step 1: Recall ORB keypoint detection syntax

    In OpenCV, ORB keypoints are detected using orb = cv2.ORB_create() and orb.detect(image, None).
  2. Step 2: Check each option

    orb = cv2.ORB_create(); keypoints = orb.detect(image, None) matches the correct syntax; others use incorrect method names or constructors.
  3. Final Answer:

    orb = cv2.ORB_create(); keypoints = orb.detect(image, None) -> Option C
  4. Quick Check:

    Correct ORB syntax = orb = cv2.ORB_create(); keypoints = orb.detect(image, None) [OK]
Hint: Use ORB_create() and detect() to find keypoints [OK]
Common Mistakes:
  • Using wrong method names like findKeypoints
  • Calling ORB() instead of ORB_create()
  • Passing wrong arguments to detect()
3. Given the following code snippet, what will be the output length of good_matches?
import cv2
orb = cv2.ORB_create()
kp1, des1 = orb.detectAndCompute(img1, None)
kp2, des2 = orb.detectAndCompute(img2, None)
matcher = cv2.BFMatcher(cv2.NORM_HAMMING)
matches = matcher.knnMatch(des1, des2, k=2)
good_matches = []
for m, n in matches:
    if m.distance < 0.75 * n.distance:
        good_matches.append(m)
print(len(good_matches))
medium
A. Total number of keypoints in img2
B. Number of matches passing the ratio test
C. Total number of keypoints in img1
D. Total number of all matches found

Solution

  1. Step 1: Understand knnMatch and ratio test

    knnMatch finds the two best matches for each descriptor. The ratio test keeps matches where the best is significantly better than the second best.
  2. Step 2: Analyze the code logic

    The loop filters matches by distance ratio, so good_matches contains only those passing the test, not all matches or keypoints.
  3. Final Answer:

    Number of matches passing the ratio test -> Option B
  4. Quick Check:

    good_matches length = matches passing ratio test [OK]
Hint: Ratio test filters matches; good_matches count = filtered matches [OK]
Common Mistakes:
  • Confusing matches with keypoints count
  • Thinking good_matches includes all matches
  • Ignoring the ratio test condition
4. Identify the error in this feature matching code snippet:
import cv2
orb = cv2.ORB_create()
kp1, des1 = orb.detectAndCompute(img1, None)
kp2, des2 = orb.detectAndCompute(img2, None)
matcher = cv2.BFMatcher(cv2.NORM_L2)
matches = matcher.match(des1, des2)
print(len(matches))
medium
A. Using cv2.NORM_L2 with ORB descriptors is incorrect
B. Missing call to detect() before detectAndCompute()
C. BFMatcher should be replaced with FlannBasedMatcher
D. match() requires k parameter for ORB descriptors

Solution

  1. Step 1: Check descriptor type and matcher norm

    ORB descriptors are binary, so BFMatcher should use cv2.NORM_HAMMING, not NORM_L2.
  2. Step 2: Identify the error

    Using NORM_L2 causes incorrect distance calculation and poor matching for ORB.
  3. Final Answer:

    Using cv2.NORM_L2 with ORB descriptors is incorrect -> Option A
  4. Quick Check:

    ORB needs NORM_HAMMING, not NORM_L2 [OK]
Hint: Use NORM_HAMMING with ORB descriptors [OK]
Common Mistakes:
  • Using wrong norm type for binary descriptors
  • Thinking detect() is needed before detectAndCompute()
  • Confusing BFMatcher with FlannBasedMatcher
5. You want to match features between two images taken from different angles. Which approach improves matching accuracy the most?
hard
A. Use ORB detector without any filtering on matches
B. Resize images to very small size before matching
C. Use random keypoints and brute force matching
D. Use SIFT detector and apply Lowe's ratio test on matches

Solution

  1. Step 1: Consider feature detector choice

    SIFT is robust to scale and rotation changes, better for different angles than ORB or random points.
  2. Step 2: Apply filtering for accuracy

    Lowe's ratio test filters out weak matches, improving accuracy significantly.
  3. Step 3: Evaluate other options

    Using ORB without filtering or random points reduces accuracy; resizing too small loses details.
  4. Final Answer:

    Use SIFT detector and apply Lowe's ratio test on matches -> Option D
  5. Quick Check:

    SIFT + ratio test = best accuracy [OK]
Hint: SIFT + Lowe's ratio test improves matching accuracy [OK]
Common Mistakes:
  • Skipping ratio test filtering
  • Using random or weak keypoints
  • Reducing image size too much