【待测】Harris角点检测:是对Moravec角点检测算子的改进;扩展了检测方向,检测结果具有旋转不变性;对滑块窗口使用了高斯系数,对离中心越近的点赋予更高的权重,以增强对噪声的干扰

void cornerHarris( InputArray src, //输入8bit单通道灰度Mat矩阵
				  OutputArray dst, //用于保存Harris角点检测结果,32位单通道,大于与src相同
				  int blockSize,   //滑块窗口的尺寸
				  int ksize,       //Sobel边缘检测滤波器大小
				  double k,        //Harris中间参数,经验值0.04~0.06
				  int borderType=BORDER_DEFAULT  //插值类型
				  );

 简单实现:

#include "core/core.hpp"  
#include "highgui/highgui.hpp"  
#include "imgproc/imgproc.hpp"  
#include "nonfree/features2d.hpp"
#include<iostream>  
 
using namespace cv;  
using namespace std;  
 
Mat image;
Mat imageGray;
int thresh=200;
int MaxThresh=255;
 
void Trackbar(int,void*);  //阈值控制
 
int main(int argc,char*argv[])  
{  
	image=imread(argv[1]);
	cvtColor(image,imageGray,CV_RGB2GRAY);
	GaussianBlur(imageGray,imageGray,Size(5,5),1); // 滤波
	namedWindow("Corner Detected");
	createTrackbar("threshold:","Corner Detected",&thresh,MaxThresh,Trackbar);
	imshow("Corner Detected",image);
	Trackbar(0,0);
	waitKey();
	return 0;
}  
 
void Trackbar(int,void*)
{
	Mat dst,dst8u,dstshow,imageSource;
	dst=Mat::zeros(image.size(),CV_32FC1);  
	imageSource=image.clone();
	cornerHarris(imageGray,dst,3,3,0.04,BORDER_DEFAULT);
	normalize(dst,dst8u,0,255,CV_MINMAX);  //归一化
	convertScaleAbs(dst8u,dstshow);
	imshow("dst",dstshow);  //dst显示
	for(int i=0;i<image.rows;i++)
	{
		for(int j=0;j<image.cols;j++)
		{
			if(dstshow.at<uchar>(i,j)>thresh)  //阈值判断
			{
				circle(imageSource,Point(j,i),2,Scalar(0,0,255),2); //标注角点
			}
		}
	}
	imshow("Corner Detected",imageSource);
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值