Table of Contents
show
Harris corner detection
cv2.cornerHarris(src, blockSize, ksize, k)
- src: The input source image (grayscale). Need to convert the image to float32 using np.float32() before passing it.
- blockSize: The size of the neighborhood considered for the Harris matrix (e.g., blockSize=2 means a 2×2 neighborhood).
- ksize: The aperture parameter for the Sobel operator (gradient computation). It refers to the size of the Sobel kernel (e.g., ksize=3).
- k: The Harris detector free parameter, typically between 0.04 and 0.06.
The parameter k determines the balance between edge detection and corner detection. It influences the decision of what qualifies as a corner versus an edge or flat region in the image:
Low k values (e.g., 0.02):
- More sensitive to corners.
- If k is too small, non-corner regions might get classified as corners.
High k values (e.g., 0.1):
- Less sensitive to corners.
- If k is too large, actual corners might be missed because the algorithm becomes less sensitive to changes in intensity.
Compute the derivative using the differentiation kernel Ix = dI/dx and Iy = dI/dy
Compute Harris Matrix

Compute Harris Corner score

‘k’ take the value between 0.04 to 0.06
- If ‘C’ is large and positive, it is corner
- If ‘C’ is large and negative, it is edge
- If |C| is small (near zero), it is flat
Shi Tomasi Corner Detection
cv2.goodFeaturesToTrack(image, maxCorners, qualityLevel, minDistance, mask=None, blockSize=3, useHarrisDetector=False, k=0.04)
- image: Input image (grayscale).
- maxCorners: Maximum number of corners to return. It will return the best ones if it detects more than this number.
- qualityLevel: Parameter for the minimum accepted quality of image corners, ranging between 0 and 1. A higher value means only stronger corners are returned.
- minDistance: Minimum possible distance between the detected corners.
- mask: Optional region of interest (ROI). Only corners inside the ROI will be detected.
- blockSize: Size of the neighborhood considered for corner detection.
- useHarrisDetector: Boolean. If True, the Harris corner detector is used instead of the Shi-Tomasi method.
- k: Free parameter of the Harris detector (used if useHarrisDetector=True).


Views: 1