Complete the code to convert the image to grayscale before processing.
gray = cv2.[1](img, cv2.COLOR_BGR2GRAY)We use cv2.cvtColor with cv2.COLOR_BGR2GRAY to convert the image to grayscale.
Complete the code to compute the Harris corner response.
dst = cv2.cornerHarris(gray, [1], 3, 0.04)
The block size parameter is usually set to 3 for Harris corner detection.
Fix the error in thresholding the Harris response to mark corners.
img[dst > [1] * dst.max()] = [0, 0, 255]
Using 0.1 as the threshold factor helps select strong corners by comparing to the max response.
Fill both blanks to normalize and convert the Harris response for visualization.
dst_norm = np.empty(dst.shape, dtype=np.float32) cv2.normalize(dst, dst_norm, [1], [2], cv2.NORM_MINMAX)
Normalization scales values between 0 and 1 for easier visualization.
Fill all three blanks to create a mask of corners and mark them on the image.
mask = dst_norm > [1] img[mask] = [[2], [3], 0]
We threshold at 0.1, then mark corners with red color [255, 128, 0].
