Feature Detection——SURF

4 篇文章 0 订阅
1 篇文章 0 订阅

Feature Detection——SURF

一.先决条件

1.SURF算法

参考博客:

https://www.cnblogs.com/jinjidexuetu/p/90ace4e8de574e3d5f4e6ac16a0dc157.html

设定Hessian行列式的阀值(下面代码中要修改的)

低于Hessian行列式阀值的点不能作为最终的特征点。在实际选择阀值时,根据实际应用中对特征点数量和精确度的要求改变阀值。阀值越大,得到的特征点的鲁棒性越好。在处理场景简单的图像时,其阀值可以适当的调低。在复杂的图像中,图像经旋转或者模糊后特征点变化的数量较大,测试需要适当提高阀值。

2.OpenCV-contrib配置

github上下载opencv对应的的opencv-contrib,然后按照教程编译即可

二.代码实现

#include <stdio.h>
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/xfeatures2d.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;
using namespace cv::xfeatures2d;
void readme();
/* @function main */
int main( int argc, char** argv )
{
  if( argc != 3 )//命令行包括三个参数
  { readme(); return -1; }
  Mat img_1 = imread( argv[1], IMREAD_GRAYSCALE );//读取第一幅图像
  Mat img_2 = imread( argv[2], IMREAD_GRAYSCALE );//第二幅图像
  if( !img_1.data || !img_2.data )//判断图像是否读取成功
  { std::cout<< " --(!) Error reading images " << std::endl; return -1; }
  //-- Step 1: Detect the keypoints using SURF Detector
  int minHessian = 400;//最小的阈值
  Ptr<SURF> detector = SURF::create( minHessian );//指针创建
  std::vector<KeyPoint> keypoints_1, keypoints_2;//关键点向量
  detector->detect( img_1, keypoints_1 );//将检测到的关键点存入向量
  detector->detect( img_2, keypoints_2 );
  //-- Draw keypoints
  Mat img_keypoints_1; Mat img_keypoints_2;//输出图像矩阵
  drawKeypoints( img_1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );//将img_1中的关键点keypoints_1画到img_keypoints_1中
  drawKeypoints( img_2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
  //-- Show detected (drawn) keypoints
  imshow("Keypoints 1", img_keypoints_1 );
  imshow("Keypoints 2", img_keypoints_2 );
  waitKey(0);
  return 0;
  }
  /* @function readme */
  void readme()
  { std::cout << " Usage: ./SURF_detector <img1> <img2>" << std::endl; }

截图:

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值