For corner detection, the key metrics are repeatability and localization accuracy. Repeatability means the detector finds the same corners under different views or lighting. Localization accuracy means the detected corners are close to the true corner points. These metrics matter because a good corner detector should reliably find important points that help in tasks like image matching or tracking.
Corner detection (Harris) in Computer Vision - Model Metrics & Evaluation
Start learning this pattern below
Jump into concepts and practice - no test required
True Corners Detected: TP = 85
False Corners Detected: FP = 15
Missed True Corners: FN = 10
Correctly Ignored Non-Corners: TN = 890
Confusion Matrix:
| Detected Corner | Not Detected |
----------|-----------------|--------------|
Corner | 85 (TP) | 10 (FN) |
No Corner | 15 (FP) | 890 (TN) |
Total samples = 85 + 15 + 10 + 890 = 1000
Precision tells us how many detected corners are actually true corners. High precision means few false corners, which is good to avoid noise.
Recall tells us how many true corners were detected. High recall means we miss very few real corners.
For example, if you want to track objects in video, missing corners (low recall) can cause tracking failure. But if you detect too many false corners (low precision), the system wastes time processing useless points.
So, a balance is needed. Harris detector parameters can be tuned to increase recall (detect more corners) or precision (detect fewer but more accurate corners).
Good: Precision and recall both above 0.8 means most detected corners are true and most true corners are found. Localization error is low (corners detected within a few pixels of true corners).
Bad: Precision below 0.5 means many false corners detected, causing noise. Recall below 0.5 means many true corners missed, losing important features. Large localization error means corners are not accurately placed.
- Ignoring localization error: Counting detected corners without checking how close they are to true corners can mislead about quality.
- Overfitting to one image: A detector tuned only for one image may not work well on others, hurting repeatability.
- Data leakage: Using test images to tune parameters inflates performance metrics.
- Accuracy paradox: High accuracy can be misleading if most pixels are non-corners (TN dominate), so precision and recall are better.
Your Harris corner detector has 98% accuracy but only 12% recall on true corners. Is it good for use?
Answer: No, because the detector misses 88% of true corners (low recall). High accuracy is misleading here since most pixels are non-corners. The detector is not reliable for finding important corners.
Practice
Solution
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.Step 2: Compare with other options
Blurring, line detection, and segmentation are different tasks not performed by Harris corner detection.Final Answer:
To find points in an image where edges meet, called corners -> Option BQuick Check:
Harris detects corners = C [OK]
- Confusing corner detection with edge detection
- Thinking Harris blurs or segments images
- Mixing up line detection with corner detection
Solution
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.Step 2: Verify other options
Other formulas either add instead of subtract or mix det and trace incorrectly.Final Answer:
R = det(M) - k * (trace(M))^2 -> Option CQuick Check:
Harris R formula uses det minus k times trace squared [OK]
- Adding instead of subtracting in the formula
- Confusing determinant with trace
- Using division instead of subtraction
corners?
import cv2
import numpy as np
img = cv2.imread('image.jpg', 0)
corners = cv2.cornerHarris(img, 2, 3, 0.04)
print(type(corners))Solution
Step 1: Understand OpenCV cornerHarris output
The function cv2.cornerHarris returns a numpy array representing the corner response for each pixel.Step 2: Check the printed type
Printing type(corners) will show <class 'numpy.ndarray'> because corners is a numpy array.Final Answer:
<class 'numpy.ndarray'> -> Option DQuick Check:
cornerHarris returns numpy array [OK]
- Assuming output is a list instead of numpy array
- Thinking output is a single number
- Confusing output type with image type
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()Solution
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.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).Final Answer:
The dilation step is missing a kernel argument -> Option AQuick Check:
cv2.dilate requires kernel [OK]
- Thinking grayscale images can't have corners
- Assuming threshold is too high
- Believing img modification is incorrect (common for grayscale)
Solution
Step 1: Understand noise impact and preprocessing
Noise can cause false corners, so applying Gaussian blur smooths the image and reduces noise effects.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.Final Answer:
Apply Gaussian blur before detection, use a moderate window size, and set a proper threshold to filter weak corners -> Option AQuick Check:
Blur + moderate window + threshold = better corners [OK]
- Ignoring noise and skipping blur
- Using too small or too large window size
- Setting threshold too low or too high
