计算机视觉基础-图像处理(下)- Task01 学习笔记

Harris⻆点检测算法思想
算法的核心是利用局部窗口在图像上进行移动,如果窗口内的灰度值有较大变化,那么这个窗口所在区域就存在角点。
Harris⻆点检测算法三步
1.当窗口同时向水平和垂直两个方向移动时,计算窗口内部的像素值变化量E(x,y);
2.计算每个窗口对应的角点响应函数R;
3.对该函数R进行阈值处理,如果其大于阈值,则表示该窗口对应一个角点特征。
对梯度图矩阵M对角化的理解
在这里插入图片描述有人觉得R与R^(-1)写反了,其实这样是可以的,只是R不再是由特征向量构成的矩阵,R的逆才是。
cornerHarris代码实现
原来import cv2 as cv 后,cv2与cv都可以使用,但是其他的模块只能使用as之后的简称。

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('./img3.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, cv2.COLOR_BGR2GRAY)
print(gray_img.shape)

# 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 = cv2.getStructuringElement(cv2.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():
                cv2.circle(image,(c,r),5,(0,0,255),0)

image = cv.cvtColor(image, cv2.COLOR_BGR2RGB)
plt.imshow(image)
plt.show()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值