图像处理下--S1Harris检测器

本文介绍了一种使用Python和OpenCV库实现Harris角点检测算法的方法。该算法通过计算图像中每个像素点的角点响应函数来确定角点位置。在实现过程中,首先将彩色图像转换为灰度图像,然后应用Harris角点检测函数,并通过阈值筛选出显著的角点。最后,使用matplotlib库可视化检测到的角点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

角点介绍
Harris检测器
代码实现

# 导入库
import cv2 as cv
import matplotlib.pyplot as plt # 或from matplotlib import pyplot as plt 
import numpy as np

# %% 参数设置
# detector parameters
blockSize=3 # 用于角点检测的领域大小即窗口尺寸
Ksize=3 # 用于计算梯度图的sobel算子的尺寸
k=0.06

image=cv.imread('Scenery.jpg')

# %% 图像参数
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,blockSize,Ksize,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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值