Surf Matching algorithm OPENCV sample code

Source: Internet
Author: User

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 );         //--&nbsp 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)         

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.