OpenCV—Harris Corner Detection
程序员文章站
2022-06-11 17:02:15
...
角点是指在各个方向上灰度值变化都非常大的区域,灰度变化也就是灰度梯度。寻找角点也就是寻找灰度梯度最大的像素点。
我们使用一个窗口在图像上滑动来计算灰度的梯度
其中为窗口函数,为某个像素点的灰度值,为窗口移动后的灰度值。
进行泰勒展开:
其中,为灰度值在两个方向的梯度。
令
即
这里使用一个便于计算的数值来判断窗口在滑动过程中是否出现角点,即
- 当很小时,表示平坦区域;
- 当时,表示边缘区域;
- 当很大时,表示角点区域;
可以使用OpenCV的 cv.cornerHarris() 可直接获得图像中每个位置像素点的计算结果R,同时指定一个合适的阈值就可以筛选出所需要的角点信息。
Parameters:
- img - Input image, it should be grayscale and float32 type.
- blockSize - It is the size of neighbourhood considered for corner detection
- ksize - Aperture parameter of Sobel derivative used.
- k - Harris detector free parameter in the equation.
实例代码:
img = cv.imread('lena.jpg')
img_gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
# Input image should be grayscale and float32 type.
img_gray = np.float32(img_gray)
# the result of Harris Corner Detection is a grayscale image with these scores.
dst = cv.cornerHarris(img_gray,2,3,0.04)
#result is dilated for marking the corners, not important
dst = cv.dilate(dst,None)
# Threshold for an optimal value, it may vary depending on the image.
img[dst>0.01*dst.max()]=[0,0,255]
img_plt = cv.cvtColor(img,cv.COLOR_BGR2RGB)
plt.figure(figsize=(10,10))
plt.imshow(img_plt)
推荐阅读
-
(四)OpenCV中的特征检测之Harris Corner检测
-
openCV特征提取及检测(一)-- Harris角点检测
-
Opencv3笔记31——Harris角点检测
-
opencv学习笔记二十五:Harris角点检测
-
OpenCV—Harris Corner Detection
-
Object detection with deep learning and OpenCV
-
OpenCV计算机视觉实战(Python)| 11、Harris角点检测
-
Inverse Geometric Transform; Gaussian and Laplacian Pyramid; Canny Filter; Harris Detection从零实现
-
openCV特征提取及检测(一)-- Harris角点检测