opencv python 角点检测 cornerHarris()

cv.cornerHarris(img, blockSize, ksize, k)

Its arguments are:

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 the Sobel derivative used.
k - Harris detector free parameter in the equation.

实验对象:t.jpg
尺寸:(1920 x 1920)
请添加图片描述

import numpy as np
import cv2 as cv

filename = 't.jpg'
img = cv.imread(filename)
img2 = img.copy()
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
gray = np.float32(gray)

# block_param test
img1 = img.copy()
dst1 = cv.cornerHarris(gray, 2, 3, 0.04)
dst1 = cv.dilate(dst1, None)
img1[dst1 > 0.001*dst1.max()] = [0, 0, 255]

img2 = img.copy()
dst2 = cv.cornerHarris(gray, 5, 3, 0.04)
dst2 = cv.dilate(dst2, None)
img2[dst2 > 0.001*dst2.max()] = [0, 0, 255]

img3 = img.copy()
dst3 = cv.cornerHarris(gray, 8, 3, 0.04)
dst3 = cv.dilate(dst3, None)
img2[dst3 > 0.001*dst3.max()] = [0, 0, 255]

plt.subplot(131)
plt.title('block_param:2')
plt.imshow(img1[:, :, ::-1])
plt.subplot(132)
plt.title('block_param:5')
plt.imshow(img2[:, :, ::-1])
plt.subplot(133)
plt.title('block_param:8')
plt.imshow(img3[:, :, ::-1])
plt.savefig('test_block_param.png')
# plt.show()
plt.close()

请添加图片描述

# ksobel_param test
img1 = img.copy()
dst1 = cv.cornerHarris(gray, 2, 3, 0.04)
dst1 = cv.dilate(dst1, None)
img1[dst1 > 0.001*dst1.max()] = [0, 0, 255]

img2 = img.copy()
dst2 = cv.cornerHarris(gray, 2, 5, 0.04)
dst2 = cv.dilate(dst2, None)
img2[dst2 > 0.001*dst2.max()] = [0, 0, 255]

img3 = img.copy()
dst3 = cv.cornerHarris(gray, 2, 7, 0.04)
dst3 = cv.dilate(dst3, None)
img2[dst3 > 0.001*dst3.max()] = [0, 0, 255]

plt.subplot(131)
plt.title('ksobel_param:3')
plt.imshow(img1[:, :, ::-1])
plt.subplot(132)
plt.title('ksobel_param:5')
plt.imshow(img2[:, :, ::-1])
plt.subplot(133)
plt.title('ksobel_param:7')
plt.imshow(img3[:, :, ::-1])
plt.savefig('test_ksobel_param.png')
# plt.show()
plt.close()

在这里插入图片描述

# k_param test
img1 = img.copy()
dst1 = cv.cornerHarris(gray, 2, 3, 0.02)
dst1 = cv.dilate(dst1, None)
img1[dst1 > 0.001*dst1.max()] = [0, 0, 255]

img2 = img.copy()
dst2 = cv.cornerHarris(gray, 2, 3, 0.04)
dst2 = cv.dilate(dst2, None)
img2[dst2 > 0.001*dst2.max()] = [0, 0, 255]

img3 = img.copy()
dst3 = cv.cornerHarris(gray, 2, 3, 0.06)
dst3 = cv.dilate(dst3, None)
img2[dst3 > 0.001*dst3.max()] = [0, 0, 255]

plt.subplot(131)
plt.title('k_param:0.02')
plt.imshow(img1[:, :, ::-1])
plt.subplot(132)
plt.title('k_param:0.04')
plt.imshow(img2[:, :, ::-1])
plt.subplot(133)
plt.title('k_param:0.06')
plt.imshow(img3[:, :, ::-1])
plt.savefig('test_k_param.png')
# plt.show()
plt.close()

请添加图片描述

# 目前针对此图的最佳参数:
dst3 = cv.cornerHarris(gray, 5, 3, 0.02)
dst3 = cv.dilate(dst3, None)
img[dst3 > 0.001*dst3.max()] = [0, 0, 255]
cv.imwrite('test.png', img)

请添加图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值