1, surf feature +flann feature matching +KNN filter match point + single-response matrix mapping
#include "stdafx.h" #include <stdio.h> #include <iostream> #include <opencv2/core/core.hpp> #include "opencv2/nonfree/ Features2d.hpp " #include <opencv2/legacy/legacy.hpp> #include <opencv2/ highgui/highgui.hpp> using namespace cv; Using namespace std; Int main ( ) { mat img_1 = imread ( "c:\\temp\\pyramidpattern.jpg", cv_load_image_grayscale ); mat img_2 = imread ( "C:\\temp\\pyramidpatterntest.bmp", CV_LOAD_IMAGE_ grayscale ); if ( !img_1.data | | !img_2.data ) { return -1; } //-- step 1: detect the keypoints using surf detector int minhessian = 400; surffeaturedetector detector ( minHessian ); 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 using flann matcher FlannBasedMatcher matcher; vector< DMatch > matches; vector<vector<DMatch>> m_knnMatches; matches.clear (); const float minRatio=1.f / 1.5f; matcher.knnmatch (descriptors_1,descriptors_2,m_knnmatches,2); for (Int i=0; i<m_knnmatches.size (); i++) { const DMatch& bestMatch=m_knnMatches[i][0]; const DMatch& betterMatch=m_knnMatches[i][1]; float distanceRatio=bestMatch.distance/betterMatch.distance; if (distanceratio<minratio)