SURF Algorithm--"robust feature of accelerated version" algorithm
steps:Feature detection--Feature description--feature matching
implementation process:(1) Feature detection: Surffeaturedetector class. Detect () function (2) Feature Description: Surfdescriptorextractor class. Compute () function (3) Feature matching: Bruteforcematcher class. The match () function is similar to the three-step implementation: A class instantiates an object (which defines a vector or mat to hold the result), invokes a function, stores the result of the calculation for next use) (4) and finally shows "match graph": drawmatches () function
Implementation code:
#include "opencv2/core/core.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/highgui/highgui.hpp
"#include <opencv2/nonfree/nonfree.hpp> #include <opencv2/legacy/legacy.hpp> #include <iostream>
using namespace CV;
using namespace Std;
int main () {//"1" Load footage graph Mat srcImage1 = Imread ("1.jpg", 1);
Mat srcImage2 = Imread ("2.jpg", 1); if (!srcimage1.data | |!srcimage2.data) {printf ("read the picture error, determine if there is a picture of the Imread function specified in the directory ~. \ n ");
return false; }//"2" uses the surf operator to detect the Hessian threshold value in the key int minhessian = 700;//surf algorithm Surffeaturedetector detector (Minhessian);//define a Surffeat Uredetector (SURF) Feature detection class object std::vector<keypoint> keyPoint1, Keypoints2;//vector template class, holds any type of dynamic array//"3"
Call the Detect function to detect the key points of the surf feature, save in the vector container detector.detect (srcImage1, keyPoint1);
Detector.detect (SrcImage2, keyPoints2);
"4" Calculation descriptor (eigenvector) surfdescriptorextractor extractor;
Mat descriptors1, Descriptors2;
Extractor.compute (SrcImage1, KeyPoint1, descriptors1); Extractor.compute (SrcImage2, KeyPoints2, descriptors2);
"5" uses Bruteforce to match//instantiate a match bruteforcematcher< l2<float> > matcher;
std::vector< Dmatch > matches;
Match two descriptors (descriptors) Matcher.match (Descriptors1, descriptors2, matches) in the picture;
"6" draws the key point from the two images to match the Mat Imgmatches; Drawmatches (SrcImage1, KeyPoint1, SrcImage2, keyPoints2, matches, imgmatches);//Draw//"7" Display Effect Diagram Imshow ("Match graph", Imgmatch
ES);
Waitkey (0);
return 0;
}