2D Features framework5(Feature Detection )
目标
在本教程中,您将学习如何:
-
使用cv :: FeatureDetector接口来查找兴趣点。特别:
- 使用cv :: xfeatures2d :: SURF及其函数cv :: xfeatures2d :: SURF :: detect执行检测过程
- 使用函数cv :: drawKeypoints绘制检测到的关键点
- 警告
- 您需要OpenCV contrib模块才能使用SURF功能(备选方案是ORB,KAZE ...功能)。
理论
程序
#include <iostream>
#include "opencv2/core.hpp"
#ifdef HAVE_OPENCV_XFEATURES2D
#include "opencv2/highgui.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/xfeatures2d.hpp"
using namespace cv;
using namespace cv::xfeatures2d;
using std::cout;
using std::endl;
int main( int argc, char* argv[] )
{
CommandLineParser parser( argc, argv, "{@input | lena11.jpg | input image}" );
Mat src = imread( parser.get<String>( "@input" ), IMREAD_GRAYSCALE );
if ( src.empty() )
{
cout << "Could not open or find the image!\n" << endl;
cout << "Usage: " << argv[0] << " <Input image>" << endl;
return -1;
}
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
//指向SURF对象的指针
Ptr<SURF> detector = SURF::create( minHessian );
//KeyPoint是一个类
std::vector<KeyPoint> keypoints;
//SURF是一个类:继承与feature2D,detect是feature2D的公有函数。
detector->detect( src, keypoints );
//-- Draw keypoints
Mat img_keypoints;
//输入,关键点,输出
drawKeypoints( src, keypoints, img_keypoints );
//-- Show detected (drawn) keypoints
imshow("SURF Keypoints", img_keypoints );
waitKey();
return 0;
}
#else
int main()
{
std::cout << "This tutorial code needs the xfeatures2d contrib module to be run." << std::endl;
return 0;
}
#endif