基于特征点的图像匹配是图像处理中经常会遇到的问题,手动选取特征点太麻烦了。比较经典常用的特征点自动提取的办法有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--特征点检测

相关文章:

  • 2021-11-27
  • 2021-09-27
  • 2021-08-11
  • 2021-10-26
  • 2021-10-17
  • 2022-12-23
  • 2022-02-11
  • 2021-12-02
猜你喜欢
  • 2021-09-16
  • 2021-09-26
  • 2021-12-22
  • 2021-12-18
  • 2021-11-09
  • 2022-01-24
相关资源
相似解决方案