首页 > 其他 > 详细

Harris角检测

时间:2020-04-15 14:24:02      阅读:68      评论:0      收藏:0      [点我收藏+]

这里有篇原理讲解的,有兴趣自己看。https://www.cnblogs.com/Jack-Elvis/p/11640931.html

在opencv有专门的函数:

CV_EXPORTS_W void cornerHarris( InputArray src, OutputArray dst, int blockSize,
                                int ksize, double k,
                                int borderType = BORDER_DEFAULT );

The function runs the Harris corner detector on the image. Similarly to cornerMinEigenVal and
cornerEigenValsAndVecs , for each pixel \((x, y)\) it calculates a \(2\times2\) gradient covariance
matrix \(M^{(x,y)}\) over a \(\texttt{blockSize} \times \texttt{blockSize}\) neighborhood. Then, it
computes the following characteristic:

\[[\texttt{dst} (x,y) = \mathrm{det} M^{(x,y)} - k \cdot \left ( \mathrm{tr} M^{(x,y)} \right )^2] \]

@param src Input single-channel 8-bit or floating-point image.
@param dst Image to store the Harris detector responses. It has the type CV_32FC1 and the same
size as src .
@param blockSize Neighborhood size (see the details on #cornerEigenValsAndVecs ).
@param ksize Aperture parameter for the Sobel operator.
@param k Harris detector free parameter. See the formula above.
@param borderType Pixel extrapolation method. See #BorderTypes.

那么具体怎么使用分以下几个步骤:

  1. 将输入图片转成灰度
cvtColor(images, gray, COLOR_BGR2GRAY);
  1. 定义参数
	double k = 0.04;
	int blocksize = 2;
	int ksize = 3;
  1. 调用具体函数
cornerHarris(gray,dst,blocksize,ksize,k);

4.对结果处理,归一化,再转成8bit

	Mat dst_norm = Mat::zeros(dst.size(),dst.type());
	normalize(dst, dst_norm, 0, 255, NORM_MINMAX, -1, Mat());
	convertScaleAbs(dst_norm,dst_norm);
  1. 在原图绘制结果
	for (int row = 0; row < images.rows; row++) {
		for (int col = 0; col < images.cols;col++) {
			int sp = dst_norm.at<uchar>(row, col);
			if (sp > 182) {
				circle(images, Point(col, row), 3, Scalar(0, 0, 255), 2, 8);
			}
		}
	}

实验效果:
原图:
技术分享图片
结果:
技术分享图片
具体要绘制那些值,可以调节阀值。

注意 harris 角检测是比较慢的。

Harris角检测

原文:https://www.cnblogs.com/cyssmile/p/12704409.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!