Harris corner detection
OpenCV has the cv2.cornerHarris()
function for detecting corners. Its arguments are as follows:
img
: The input image, which must be grayscale and have thefloat32
type.blockSize
: This is the size of the neighborhood considered for corner detection.ksize
: The aperture parameter of the Sobel derivative used.k
: The free Harris detector parameter used in the equation.
The following is an example program that implements Harris corner detection:
import cv2 import numpy as np import matplotlib.pyplot as plt img = cv2.imread('/home/pi/book/dataset/4.1.05.tiff', 0) img = np.float32(img) dst = cv2.cornerHarris(img, 2, 3, 0.04) ret, dst = cv2.threshold(dst, 0.01*dst.max(), 255, 0) dst = np.uint8(dst) plt.imshow(dst, cmap='gray') plt.axis('off') plt.show()
In the preceding program, we coverted the image into 32-bit float format and then we fed it to the corner detection function. Then, we threshholded the...