Goal
In this tutorial you will learn how to:
- Use the cv::FeatureDetector interface in order to find interest points. Specifically:
- Use the cv::xfeatures2d::SURF and its function cv::xfeatures2d::SURF::detect to perform the detection process
- Use the function cv::drawKeypoints to draw the detected keypoints
Theory
Code
This tutorial code's is shown lines below.
#include <stdio.h>
#include <iostream>
#include "opencv2/xfeatures2d.hpp"
using namespace cv::xfeatures2d;
void readme();
int main( int argc, char** argv )
{
if( argc != 3 )
{ readme(); return -1; }
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
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 );
Mat img_keypoints_1;
Mat img_keypoints_2;
imshow(
"Keypoints 1", img_keypoints_1 );
imshow(
"Keypoints 2", img_keypoints_2 );
return 0;
}
void readme()
{ std::cout << " Usage: ./SURF_detector <img1> <img2>" << std::endl; }
Explanation
Result
Here is the result of the feature detection applied to the first image:
And here is the result for the second image: