I've written about the blog:http://blog.csdn.net/sangni007/article/details/7482960 of learning surf algorithms before.
But the code is cumbersome, and it involves the Flann algorithm (where the random kdtree+knn), although it can be seen, but more laborious, today in the document found a simplified version:
1.SurfFeatureDetector detector (Minhessian); structure Surf detector;
Detector.detect (img_1, keypoints_1); Detector.detect (Img_2, keypoints_2);
2.SurfDescriptorExtractor Extractor; Extract description structure
Mat Descriptors_1, descriptors_2;
Extractor.compute (img_1, Keypoints_1, descriptors_1); Extractor.compute (Img_2, keypoints_2, descriptors_2);
3.bruteforcematcher< l2<float> > matcher; the matching structure!!!! Can measure distances directly from violence
std::vector< Dmatch > matches;
Matcher.match (Descriptors_1, descriptors_2, matches);
Documentation: HTTP://OPENCV.ITSEEZ.COM/MODULES/GPU/DOC/FEATURE_DETECTION_AND_DESCRIPTION.HTML?HIGHLIGHT=BRUTEFORCE#GPU:: Bruteforcematcher_gpu
Ps:opencv you are too tough!!! Only I can't think of, Wood has you can't do! I'm really on my knees!
[CPP]View PlainCopyprint?
- /**
- * @file Surf_descriptor
- * @brief SURF Detector + Descritpor + bruteforce Matcher + drawing matches with OpenCV functions
- * @author A. Huaman
- */
- #include <stdio.h>
- #include <iostream>
- #include "opencv2/core/core.hpp"
- #include "opencv2/features2d/features2d.hpp"
- #include "opencv2/highgui/highgui.hpp"
- Using namespace CV;
- Using namespace std;
- void Readme ();
- /**
- * @function Main
- * @brief Main function
- */
- int main ( int argc, char** argv)
- {
- //if (argc! = 3)
- //{return-1;}
- Mat img_1 = Imread ( "d:/src.jpg", Cv_load_image_grayscale);
- Mat img_2 = Imread ( "d:/demo.jpg", Cv_load_image_grayscale);
- if (!img_1.data | |!img_2.data)
- { return-1;}
- //--Step 1:detect the keypoints using SURF Detector
- int Minhessian = 400;
- double T=gettickcount ();
- Surffeaturedetector detector (Minhessian);
- Std::vector<keypoint> Keypoints_1, keypoints_2;
- Detector.detect (img_1, keypoints_1);
- Detector.detect (Img_2, keypoints_2);
- //--Step 2:calculate descriptors (feature vectors)
- Surfdescriptorextractor extractor;
- Mat Descriptors_1, descriptors_2;
- Extractor.compute (img_1, Keypoints_1, descriptors_1);
- Extractor.compute (Img_2, keypoints_2, descriptors_2);
- //--Step 3:matching descriptor vectors with a brute force Matcher
- bruteforcematcher< l2<float> > Matcher;
- std::vector< Dmatch > matches;
- Matcher.match (Descriptors_1, descriptors_2, matches);
- T=gettickcount ()-t;
- T=t*1000/gettickfrequency ();
- //--Draw matches
- Mat img_matches;
- Drawmatches (img_1, Keypoints_1, Img_2, keypoints_2, matches, img_matches);
- cout<<"Cost Time:" <<t<<endl;
- //--Show detected matches
- Imshow ("Matches", img_matches);
- Waitkey (0);
- return 0;
- }
- /**
- * @function Readme
- */
- void Readme ()
- {std::cout << "Usage:./surf_descriptor
The match keypoints in the image is not filtered. Cause too many match points
Document Address: Http://opencv.itseez.com/doc/tutorials/features2d/feature_description/feature_description.html?highlight=description
There is also a version in the document with the positioning and filtering match,
: Http://opencv.itseez.com/doc/tutorials/features2d/feature_homography/feature_homography.html?highlight=drawmatchesflags
from:http://blog.csdn.net/yangtrees/article/details/7544133
Learning Opencv--surf Simplified version