Bird
Raised Fist0
Computer Visionml~20 mins

Corner detection (Harris) 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
🎖️
Harris Corner Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What does the Harris corner detector primarily measure?
The Harris corner detector is used in computer vision to find corners in images. What is the main quantity it measures to detect corners?
AThe change in intensity in all directions around a pixel
BThe average color value of a pixel neighborhood
CThe distance between edges in the image
DThe brightness of the pixel compared to the image mean
Attempts:
2 left
💡 Hint
Think about what makes a corner different from an edge or flat area.
Predict Output
intermediate
2:00remaining
Output of Harris response matrix calculation
Given the following code snippet that computes the Harris response matrix R for a pixel, what is the value of R?
Computer Vision
import numpy as np
Ix = 2
Iy = 3
Ixx = Ix * Ix
Iyy = Iy * Iy
Ixy = Ix * Iy
k = 0.04
M = np.array([[Ixx, Ixy], [Ixy, Iyy]])
R = np.linalg.det(M) - k * (np.trace(M) ** 2)
print(round(R, 2))
A0.44
B1.44
C0.0
D-6.76
Attempts:
2 left
💡 Hint
Calculate determinant and trace carefully.
Model Choice
advanced
1:30remaining
Choosing parameters for Harris corner detection
Which parameter adjustment will increase the sensitivity of the Harris corner detector to detect more corners in an image?
AIncrease the threshold for corner response R
BIncrease the value of the Harris detector free parameter k
CDecrease the window size used for gradient summation
DUse a larger Gaussian smoothing before computing gradients
Attempts:
2 left
💡 Hint
Think about how window size affects local detail detection.
Metrics
advanced
1:30remaining
Evaluating Harris corner detection results
After running Harris corner detection, you get a set of corner points. Which metric best describes the quality of detected corners compared to ground truth corners?
ARecall (ratio of detected corners to total ground truth corners)
BPrecision (ratio of correctly detected corners to all detected corners)
CAccuracy (ratio of correct detections to total image pixels)
DMean squared error between detected corner coordinates and ground truth
Attempts:
2 left
💡 Hint
Consider how many detected corners are actually correct.
🔧 Debug
expert
2:30remaining
Debugging incorrect Harris corner detection output
You implemented Harris corner detection but the output shows no corners detected. Which of the following code mistakes would cause this issue?
Computer Vision
import cv2
import numpy as np
img = cv2.imread('image.jpg', 0)
Ix = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=3)
Iy = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=3)
Ixx = Ix * Ix
Iyy = Iy * Iy
Ixy = Ix * Iy
k = 0.04
window_size = 3
height, width = img.shape
R = np.zeros((height, width))
for y in range(window_size, height - window_size):
    for x in range(window_size, width - window_size):
        Sxx = np.sum(Ixx[y - window_size:y + window_size + 1, x - window_size:x + window_size + 1])
        Syy = np.sum(Iyy[y - window_size:y + window_size + 1, x - window_size:x + window_size + 1])
        Sxy = np.sum(Ixy[y - window_size:y + window_size + 1, x - window_size:x + window_size + 1])
        M = np.array([[Sxx, Sxy], [Sxy, Syy]])
        R[y, x] = np.linalg.det(M) - k * (np.trace(M) ** 2)
threshold = 0.01 * R.max()
corners = np.where(R > threshold)
print(len(corners[0]))
AThe threshold is set too high, filtering out all corners
BThe image is read in color mode instead of grayscale
CThe Sobel operator is applied with wrong kernel size
DThe window size is too large, causing sums to be zero
Attempts:
2 left
💡 Hint
Check the threshold relative to the maximum R value.

Practice

(1/5)
1. What is the main goal of the Harris corner detection algorithm in computer vision?
easy
A. To detect straight lines in an image
B. To find points in an image where edges meet, called corners
C. To blur the image for noise reduction
D. To segment the image into different color regions

Solution

  1. Step 1: Understand the purpose of Harris corner detection

    Harris corner detection is designed to find corners, which are points where two edges meet in an image.
  2. Step 2: Compare with other options

    Blurring, line detection, and segmentation are different tasks not performed by Harris corner detection.
  3. Final Answer:

    To find points in an image where edges meet, called corners -> Option B
  4. Quick Check:

    Harris detects corners = C [OK]
Hint: Corners are where edges meet, Harris finds these points [OK]
Common Mistakes:
  • Confusing corner detection with edge detection
  • Thinking Harris blurs or segments images
  • Mixing up line detection with corner detection
2. Which of the following is the correct formula for the Harris corner response R?
easy
A. R = det(M) + k * (trace(M))^2
B. R = trace(M) - k * det(M)
C. R = det(M) - k * (trace(M))^2
D. R = det(M) / trace(M)

Solution

  1. Step 1: Recall the Harris corner response formula

    The Harris response is calculated as R = det(M) - k * (trace(M))^2, where M is the second moment matrix and k is a sensitivity factor.
  2. Step 2: Verify other options

    Other formulas either add instead of subtract or mix det and trace incorrectly.
  3. Final Answer:

    R = det(M) - k * (trace(M))^2 -> Option C
  4. Quick Check:

    Harris R formula uses det minus k times trace squared [OK]
Hint: Remember: R = det minus k times trace squared [OK]
Common Mistakes:
  • Adding instead of subtracting in the formula
  • Confusing determinant with trace
  • Using division instead of subtraction
3. Given the following Python code snippet using OpenCV, what will be the output type of corners?
import cv2
import numpy as np
img = cv2.imread('image.jpg', 0)
corners = cv2.cornerHarris(img, 2, 3, 0.04)
print(type(corners))
medium
A. <class 'float'>
B. <class 'list'>
C. <class 'int'>
D. <class 'numpy.ndarray'>

Solution

  1. Step 1: Understand OpenCV cornerHarris output

    The function cv2.cornerHarris returns a numpy array representing the corner response for each pixel.
  2. Step 2: Check the printed type

    Printing type(corners) will show <class 'numpy.ndarray'> because corners is a numpy array.
  3. Final Answer:

    <class 'numpy.ndarray'> -> Option D
  4. Quick Check:

    cornerHarris returns numpy array [OK]
Hint: cornerHarris returns a numpy array of responses [OK]
Common Mistakes:
  • Assuming output is a list instead of numpy array
  • Thinking output is a single number
  • Confusing output type with image type
4. In the code below, why does the Harris corner detection not highlight any corners?
import cv2
import numpy as np
img = cv2.imread('image.jpg', 0)
corners = cv2.cornerHarris(img, 2, 3, 0.04)
corners = cv2.dilate(corners, None)
img[corners > 0.01 * corners.max()] = 255
cv2.imshow('Corners', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
medium
A. The dilation step is missing a kernel argument
B. The threshold 0.01 * corners.max() is too high, no pixels pass
C. The image is grayscale, so corners cannot be detected
D. The assignment img[corners > threshold] = 255 modifies the original image incorrectly

Solution

  1. Step 1: Analyze the dilation step

    The line corners = cv2.dilate(corners, None) fails with a TypeError because cv2.dilate requires a kernel (e.g., np.ones((3,3), np.uint8)). None is invalid, causing the code to crash before imshow.
  2. Step 2: Rule out other options

    Grayscale works fine (A wrong), 0.01 threshold is standard (B wrong), direct modification to 255 is common for grayscale marking (D ok).
  3. Final Answer:

    The dilation step is missing a kernel argument -> Option A
  4. Quick Check:

    cv2.dilate requires kernel [OK]
Hint: cv2.dilate needs kernel like np.ones((3,3)); None causes TypeError [OK]
Common Mistakes:
  • Thinking grayscale images can't have corners
  • Assuming threshold is too high
  • Believing img modification is incorrect (common for grayscale)
5. You want to detect strong corners in a noisy image using Harris corner detection. Which combination of steps will best improve corner detection accuracy?
hard
A. Apply Gaussian blur before detection, use a moderate window size, and set a proper threshold to filter weak corners
B. Use raw noisy image, large window size, and low threshold for more corners
C. Apply Gaussian blur before detection, use a smaller window size, and increase threshold
D. Skip blurring, use smallest window size, and no threshold to detect all corners

Solution

  1. Step 1: Understand noise impact and preprocessing

    Noise can cause false corners, so applying Gaussian blur smooths the image and reduces noise effects.
  2. Step 2: Choose window size and threshold carefully

    A moderate window size balances detail and noise, and a proper threshold filters out weak corners, improving accuracy.
  3. Final Answer:

    Apply Gaussian blur before detection, use a moderate window size, and set a proper threshold to filter weak corners -> Option A
  4. Quick Check:

    Blur + moderate window + threshold = better corners [OK]
Hint: Blur first, then moderate window and threshold for best corners [OK]
Common Mistakes:
  • Ignoring noise and skipping blur
  • Using too small or too large window size
  • Setting threshold too low or too high