opencv_python图像处理——Harris特征点检测器-兴趣点检测

Harris角点检测的性质:
1)阈值决定角点的数量
2)Harris角点检测算子对亮度和对比度的变化不敏感(光照不变性)
3)Harris角点检测算子具有旋转不变性
4)Harris角点检测算子不具有尺度不变性

import cv2 as cv
from matplotlib import pyplot as plt
import numpy as np

# detector parameters
block_size = 3
sobel_size = 3
k = 0.06

image = cv.imread('img/test_harris.jpeg')

print(image.shape)
height = image.shape[0]
width = image.shape[1]
channels = image.shape[2]
print("width: %s  height: %s  channels: %s" % (width, height, channels))

gray_img = cv.cvtColor(image, cv.COLOR_BGR2GRAY)

# modify the data type setting to 32-bit floating point
gray_img = np.float32(gray_img)

# detect the corners with appropriate values as input parameters
corners_img = cv.cornerHarris(gray_img, block_size, sobel_size, k)

# result is dilated for marking the corners, not necessary
kernel = cv.getStructuringElement(cv.MORPH_RECT, (3, 3))
dst = cv.dilate(corners_img, kernel)

# Threshold for an optimal value, marking the corners in Green
# image[corners_img>0.01*corners_img.max()] = [0,0,255]

for r in range(height):
    for c in range(width):
        pix = dst[r, c]
        if pix > 0.05 * dst.max():
            cv.circle(image, (c, r), 5, (0, 0, 255), 0)

image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
plt.imshow(image)
plt.show()

原图:
在这里插入图片描述
结果图:
在这里插入图片描述
不得不提,运行时间挺长的,不是实时出结果。

参考链接:
Datawhale 计算机视觉基础-图像处理(下)- Task01 Harris特征点检测器-兴趣点检测

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章