Surf algorithm for feature detection and matching of OPENCV learning notes __

Source: Internet
Author: User
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;
 }


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.