Learn Opencv--surf simplified version

Source: Internet
Author: User

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?
  1. /**
  2. * @file Surf_descriptor
  3. * @brief SURF Detector + Descritpor + bruteforce Matcher + drawing matches with OpenCV functions
  4. * @author A. Huaman
  5. */
  6. #include <stdio.h>
  7. #include <iostream>
  8. #include "opencv2/core/core.hpp"
  9. #include "opencv2/features2d/features2d.hpp"
  10. #include "opencv2/highgui/highgui.hpp"
  11. Using namespace CV;
  12. Using namespace std;
  13. void Readme ();
  14. /**
  15. * @function Main
  16. * @brief Main function
  17. */
  18. int main ( int argc, char** argv)
  19. {
  20. //if (argc! = 3)
  21. //{return-1;}
  22. Mat img_1 = Imread ( "d:/src.jpg", Cv_load_image_grayscale);
  23. Mat img_2 = Imread ( "d:/demo.jpg", Cv_load_image_grayscale);
  24. if (!img_1.data | |!img_2.data)
  25. { return-1;}
  26. //--Step 1:detect the keypoints using SURF Detector
  27. int Minhessian = 400;
  28. double T=gettickcount ();
  29. Surffeaturedetector detector (Minhessian);
  30. Std::vector<keypoint> Keypoints_1, keypoints_2;
  31. Detector.detect (img_1, keypoints_1);
  32. Detector.detect (Img_2, keypoints_2);
  33. //--Step 2:calculate descriptors (feature vectors)
  34. Surfdescriptorextractor extractor;
  35. Mat Descriptors_1, descriptors_2;
  36. Extractor.compute (img_1, Keypoints_1, descriptors_1);
  37. Extractor.compute (Img_2, keypoints_2, descriptors_2);
  38. //--Step 3:matching descriptor vectors with a brute force Matcher
  39. bruteforcematcher< l2<float> > Matcher;
  40. std::vector< Dmatch > matches;
  41. Matcher.match (Descriptors_1, descriptors_2, matches);
  42. T=gettickcount ()-t;
  43. T=t*1000/gettickfrequency ();
  44. //--Draw matches
  45. Mat img_matches;
  46. Drawmatches (img_1, Keypoints_1, Img_2, keypoints_2, matches, img_matches);
  47. cout<<"Cost Time:" <<t<<endl;
  48. //--Show detected matches
  49. Imshow ("Matches", img_matches);
  50. Waitkey (0);
  51. return 0;
  52. }
  53. /**
  54. * @function Readme
  55. */
  56. void Readme ()
  57. {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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.