【问题标题】:Non-maximum suppression in corner detection角点检测中的非最大抑制
【发布时间】:2018-10-05 14:09:27
【问题描述】:

我正在用 Python 编写 Harris 角点检测算法,并且正在执行非最大抑制以检测角点。

我找到了角响应函数R,当我打印出来时它似乎是准确的,但是我不知道从这里去哪里。我大致了解非最大抑制的概念,即将窗口内具有最高强度的像素设置为角点,其余设置为 0。虽然我不确定如何在实现方面进行此操作。

计算后,我是否会使用它创建的地图将原始图像中的这些像素设置为特定颜色(以指示哪些是角)?

到目前为止我的代码如下:

import matplotlib.pyplot as plt
import numpy as np
import cv2

# Load image
img = cv2.imread('mountains.jpg')

# Make a copy of the image
img_copy = np.copy(img)

# Convert image from BGR to RGB
img_copy = cv2.cvtColor(img_copy, cv2.COLOR_BGR2RGB)

# Convert to grayscale for filtering
gray = cv2.cvtColor(img_copy, cv2.COLOR_RGB2GRAY)

# Copy grayscale and convert to float32 type
gray_1 = np.copy(gray)
gray_1 = np.float32(gray_1)
img_1 = np.copy(img)

# Compute derivatives in both x and y directions
sobelx = cv2.Sobel(gray_1, cv2.CV_64F, 1, 0, ksize=5)
sobely = cv2.Sobel(gray_1, cv2.CV_64F, 0, 1, ksize=5)

# Determine M = [A C ; C B] performing element-wise multiplication
A = np.square(sobelx)
B = np.square(sobely)
C = np.multiply(sobelx, sobely)

# Apply gaussian filter to matrix components
gauss = np.array([[1, 2, 1],
                  [2, 4, 2], 
                  [1, 2, 1]])/16

A_fil = cv2.filter2D(A, cv2.CV_64F, gauss)
B_fil = cv2.filter2D(B, cv2.CV_64F, gauss)
C_fil = cv2.filter2D(C, cv2.CV_64F, gauss)

# Calculate determinant
det = A_fil * B_fil - (C_fil ** 2)

# Calculate trace (alpha = 0.04 to 0.06)
alpha = 0.04
trace = alpha * (A_fil + B_fil) ** 2

# Using determinant and trace, calculate corner response function
R = det - trace

# Display corner response function
f, ax1 = plt.subplots(1, 1, figsize=(20,10))

ax1.set_title('Corner response fuction')
ax1.imshow(R, cmap="gray")

(注意:堆栈溢出图像无法正常工作)

输出:

使用 OpenCV 的 Harris 角点检测:

【问题讨论】:

    标签: python opencv


    【解决方案1】:

    已经有一段时间了,所以您可能已经有了答案,但由于尚未有人回复,我将把它留给后代。

    这是一个简单的非最大抑制算法:

    • 将您的图像分割成图块(例如 64 x 48 像素)
    • 选择最小分隔空间(例如,特征之间 >= 10 像素)
    • 选择每个图块的最大特征数(例如 5 个)

    按 R(从高到低)对每个窗口图块中的要素进行排序,然后仅接受(最多)5 个与其他要素至少相距 10 像素的最大要素。您将无法保证窗块之间的最小距离为 10 像素,但这是一个合理的开始。

    【讨论】:

      猜你喜欢
      • 2021-03-10
      • 2013-03-25
      • 1970-01-01
      • 1970-01-01
      • 2011-10-19
      • 2017-08-10
      • 2014-12-28
      • 2014-07-22
      • 1970-01-01
      相关资源
      最近更新 更多