opencv开发笔记(十五):特征检测十大方法之SURF算法

SURF算法原理:

1、构建hession矩阵构造高斯金字塔尺度空间,使特征点具备尺度无关性

2、利用非极大值抑制初步确定特征点

3、精确定位极值点

4、选取特征点的主方向

5、构建surf特征点描述算子

// SURF算法特征点检测.cpp : 定义控制台应用程序的入口点。
#include "stdafx.h"
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
//#include "opencv2/nonfree/nonfree.hpp"
#include <iostream>
using namespace cv;
using namespace std;

  //-----------------------------------【main( )函数】--------------------------------------------
  //   描述:控制台应用程序的入口函数,我们的程序从这里开始执行
  //-----------------------------------------------------------------------------------------------
int main(int argc, char** argv)
{
//【0】改变console字体颜色    
system("color 2F");

//【1】载入源图片并显示
Mat srcImage1 = imread("E:\\Pictures\\1.jpg", 1);
Mat srcImage2 = imread("E:\\Pictures\\2.jpg", 1);
if (!srcImage1.data || !srcImage2.data)//检测是否读取成功
{
printf("读取图片错误,请确定目录下是否有imread函数指定名称的图片存在~! \n"); return false;
}
imshow("原始图1", srcImage1);
imshow("原始图2", srcImage2);

//【2】定义需要用到的变量和类
int minHessian = 400;//定义SURF中的hessian阈值特征点检测算子
//SurfFeatureDetector detector(minHessian);//定义一个SurfFeatureDetector(SURF) 特征检测类对象
//std::vector<KeyPoint> keypoints_1, keypoints_2;//vector模板类是能够存放任意类型的动态数组,能够增加和压缩数据

  //【3】调用detect函数检测出SURF特征关键点,保存在vector容器中
//detector.detect(srcImage1, keypoints_1);
//detector.detect(srcImage2, keypoints_2);
/*----------------------------------------------------------nonfree模块丢失用不了SurfFeatureDetector接口-------------------------------------------------------*/

vector<KeyPoint> keypoints_1, keypoints_2;
Ptr<FeatureDetector> dector = FastFeatureDetector::create(minHessian);
dector->detect(srcImage1, keypoints_1);
dector->detect(srcImage2, keypoints_2);


//【4】绘制特征关键点.
Mat img_keypoints_1; Mat img_keypoints_2;
drawKeypoints(srcImage1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT);
drawKeypoints(srcImage2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT);


//【5】显示效果图
imshow("特征点检测效果图1", img_keypoints_1);
imshow("特征点检测效果图2", img_keypoints_2);

waitKey(0);
return 0;
}






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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值