opencv-Harris角点检测

opencv-Harris角点检测

1、角点检测理论

自相关函数
(ps:还有很多理论的数学函数,贴一个最主要的)

没有扎实的理论基础,公式可以暂时不需要理解。对于上层应用开发人员,会用API和调参应该就行了。

2、代码

(ps:这是opencv特征检测里一小节课程,代码大多使用api,所以不注释了,以后回来复习的时候应该也不会多费力)

程序用了trackbar,更好的演示程序和观察阈值对角点检测的影响。

#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;

const char * output_title = "output";
int thresh = 120;
int max_count = 255;
void Harris(int,void*);
Mat src,gray_src;
int main()
{
	src = imread("2.jpg");
	namedWindow("src", 0);
	imshow("src",src);

	namedWindow(output_title, 0);
	cvtColor(src, gray_src, CV_BGR2GRAY);
	
	createTrackbar("Threash",output_title,&thresh,max_count,Harris);
	Harris(0, 0);


	waitKey(0);
	return 0;
}

void Harris(int,void*)
{
	Mat norm_dst,normScaledst;
	Mat dst = Mat::zeros(gray_src.size(), CV_32FC1);

	int block = 5;
	int ksize = 27;
	double k = 0.04;
	cornerHarris(gray_src, dst, block, ksize, k, BORDER_DEFAULT);
	normalize(dst, norm_dst, 0, 255, NORM_MINMAX, CV_32FC1);
	convertScaleAbs(norm_dst, normScaledst);
	
	Mat res = src.clone();
	for (int i = 0; i < res.rows; i++)
	{
		uchar* currentRow = normScaledst.ptr(i);
		for (int j = 0; j < res.cols; j++)
		{
			int value = (int)*currentRow;
			if (value > thresh)
			{
				circle(res, Point(i, j), 0.5, Scalar(0, 0, 255), 1, 8, 0);
			}
			currentRow++;
		}
	}
	imshow(output_title, res);
}

3、效果截图

运行截图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值