示例程序043--特征点检测

基于特征点的图像匹配是图像处理中经常会遇到的问题,手动选取特征点太麻烦了。比较经典常用的特征点自动提取的办法有Harris特征、SIFT特征、SURF特征。

 

    先介绍利用SURF特征的特征点检测,具体过程是:

        1.使用 FeatureDetector 接口来发现感兴趣点。

        2.使用 SurfFeatureDetector 以及它的函数 detect 来实现检测过程

        3.使用函数 drawKeypoints 来绘制检测到的关键点

    虽然代码和函数都很简单,但是其实我现在对SURF还不了解,也不知道提取出来的特征点具体是根据什么特征。今后用到再详细研究吧。

 

     代码和部分注释:

// 052 特征点检测.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"

 

using namespace cv;

 


int main( int argc, char** argv )
{

 Mat img_1 = imread("Lena.png", CV_LOAD_IMAGE_GRAYSCALE );
  Mat img_2 = imread("HappyFish.jpg", CV_LOAD_IMAGE_GRAYSCALE );

 

  if( !img_1.data || !img_2.data )
  { std::cout<< " --(!) Error reading images " << std::endl; return -1; }

 

  //Threshold for hessian keypoint detector used in SURF
  int minHessian = 400;

 

  //SurfFeatureDetector:用 SURF 函数实现的特征检测子封装类
  SurfFeatureDetector detector( minHessian );

 

  std::vector<KeyPoint> keypoints_1, keypoints_2;

  //detect函数可以检测出SURF特征的关键点,保存在vector容器中
  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 );
  drawKeypoints( img_2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT );

 

  imshow("Keypoints 1", img_keypoints_1 );
  imshow("Keypoints 2", img_keypoints_2 );

  waitKey(0);

  return 0;
  }


运行结果:

示例程序043--特征点检测

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值