Feature: Distinctive pattern in an image that can be reliably detected
Good features:
Why detect features?
Corner: Point where two edges meet (intensity change in multiple directions)
Properties:
Use case: Tracking, matching, calibration
Harris algorithm: Measures corner-ness using gradient matrix
Formula: R = det(M) - k × trace(M)²
R = det(M) - k × trace(M)²
Where M is gradient matrix:
R > threshold: Corner detected
import cv2import numpy as npgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)gray = np.float32(gray)# detect harris corners#ans: corners = cv2.cornerHarris(gray, blockSize=2, ksize=3, k=0.04)# blockSize: neighborhood size#ans: size of window to compute gradient# ksize: Sobel kernel size#ans: for computing gradients (3, 5, 7)# k: Harris parameter#ans: typically 0.04-0.06, sensitivity parameter# threshold to mark cornerscorners = cv2.dilate(corners, None)img[corners > 0.01 * corners.max()] = [0, 0, 255]#ans: marks corners in red where response > threshold
Shi-Tomasi: Improved Harris, better for tracking
Formula: R = min(λ1, λ2) where λ are eigenvalues
R = min(λ1, λ2)
Advantage: More reliable corner selection
Use case: Optical flow, tracking
# detect good features to track#ans: corners = cv2.goodFeaturesToTrack(gray, maxCorners=100, qualityLevel=0.01, minDistance=10)# maxCorners: maximum number to return#ans: 100 strongest corners# qualityLevel: minimum quality (0-1)#ans: 0.01 means keep corners > 1% of best# minDistance: minimum pixel distance between corners#ans: 10 pixels apart# draw corners#ans: for corner in corners:#ans: x, y = corner.ravel()#ans: cv2.circle(img, (int(x), int(y)), 3, (0, 255, 0), -1)
FAST: Features from Accelerated Segment Test
Algorithm:
Advantage: Very fast, real-time capable
# create FAST detector#ans: fast = cv2.FastFeatureDetector_create()# detect keypoints#ans: keypoints = fast.detect(gray, None)# draw keypoints#ans: img_kp = cv2.drawKeypoints(img, keypoints, None, color=(0, 255, 0))# adjust thresholdfast.setThreshold(30)#ans: higher threshold = fewer keypoints, stronger corners# control non-max suppressionfast.setNonmaxSuppression(True)#ans: removes adjacent weak corners
Blob: Region significantly different from surroundings
SimpleBlobDetector: Detects bright/dark circular regions
Parameters:
# create blob detector with default params#ans: detector = cv2.SimpleBlobDetector_create()# detect blobs#ans: keypoints = detector.detect(gray)# draw blobs#ans: img_blobs = cv2.drawKeypoints(img, keypoints, None, (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)# custom parametersparams = cv2.SimpleBlobDetector_Params()params.filterByArea = Trueparams.minArea = 100params.maxArea = 5000params.filterByCircularity = Trueparams.minCircularity = 0.8#ans: detector = cv2.SimpleBlobDetector_create(params)#ans: detects circular blobs 100-5000 pixels, circularity > 0.8
# what is a corner?#ans: point with high gradient in multiple directions# why detect features?#ans: object recognition, matching, tracking, stitching# what does Harris detect?#ans: corners using gradient matrix# difference between Harris and Shi-Tomasi?#ans: Shi-Tomasi uses min(λ1,λ2), better for tracking# what is FAST?#ans: fast corner detector using circle of pixels
# what is a blob?#ans: region significantly different from surroundings# what is k parameter in Harris?#ans: sensitivity, typically 0.04-0.06# what is qualityLevel in goodFeaturesToTrack?#ans: minimum quality as fraction of best corner (0-1)# why FAST is fast?#ans: simple comparison test, no gradient computation# what does minDistance parameter do?#ans: ensures corners are at least N pixels apart
# detect Harris cornersgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)gray = np.float32(gray)#ans: corners = cv2.cornerHarris(gray, 2, 3, 0.04)# detect Shi-Tomasi corners#ans: corners = cv2.goodFeaturesToTrack(gray, 100, 0.01, 10)# create FAST detector#ans: fast = cv2.FastFeatureDetector_create()#ans: keypoints = fast.detect(gray, None)
# detect blobs#ans: detector = cv2.SimpleBlobDetector_create()#ans: keypoints = detector.detect(gray)# draw Harris cornerscorners = cv2.cornerHarris(gray, 2, 3, 0.04)corners = cv2.dilate(corners, None)#ans: img[corners > 0.01 * corners.max()] = [0, 0, 255]# draw Shi-Tomasi cornerscorners = cv2.goodFeaturesToTrack(gray, 100, 0.01, 10)#ans: for corner in corners:#ans: x, y = corner.ravel()#ans: cv2.circle(img, (int(x), int(y)), 3, (255, 0, 0), -1)
# adjust FAST thresholdfast = cv2.FastFeatureDetector_create()#ans: fast.setThreshold(50)#ans: keypoints = fast.detect(gray, None)# detect top 50 Shi-Tomasi corners#ans: corners = cv2.goodFeaturesToTrack(gray, 50, 0.01, 10)# custom blob parametersparams = cv2.SimpleBlobDetector_Params()#ans: params.filterByArea = True#ans: params.minArea = 50#ans: params.maxArea = 1000#ans: detector = cv2.SimpleBlobDetector_create(params)
Google tag (gtag.js)