title: How to compare two group keypoint in OpenCV
body: <p>I want find something from a image.</p>
  
  <p>Just like face detect,but not detected face,I want detected other something.</p>
  
  <p>so I use SURF arithmetic find Key Point,and use FLANN arithmetic match Key Point.</p>
  
  <p>but I how to know image is good match?</p>
  
  <p>I think if source image<code>s Key Points distribute and template image</code>s Key Points distribute need very similarity.then the two iamge match.but how to do?</p>
  
  <pre><code>int main( int argc, char** argv )
  {
      std::string templateStr = "D:\\template2.jpg";
      std::string srcString = "D:\\IMG_0284.jpg";
      Mat img_1 = imread(templateStr, CV_LOAD_IMAGE_GRAYSCALE );
      Mat img_2 = imread(srcString, CV_LOAD_IMAGE_GRAYSCALE );
  
  
      //-- Step 1: Detect the keypoints using SURF Detector
      int minHessian = 500;
  
      SurfFeatureDetector detector( minHessian );
  
      std::vector&lt;KeyPoint&gt; keypoints_1, keypoints_2;
      detector.detect( img_1, keypoints_1 );
      detector.detect( img_2, keypoints_2 );
  
  
      //show keypoint,only test
      Mat img_11 = imread(templateStr, CV_LOAD_IMAGE_GRAYSCALE );
      Mat img_21 = imread(srcString, CV_LOAD_IMAGE_GRAYSCALE );
  
      drawKeypoints (img_11, keypoints_1, img_11, cv::Scalar::all(0), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
      drawKeypoints (img_21, keypoints_2, img_21, cv::Scalar::all(0), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
  
      cv::namedWindow ("img_11");
      cv::imshow ("img_11",img_11);
      cv::namedWindow ("img_21");
      cv::imshow ("img_21",img_21);
      cv::waitKey (0);
  
  
  
      //-- 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;
      std::vector&lt;DMatch&gt; matches;
      tt = (double)cvGetTickCount();
      matcher.match( descriptors_1, descriptors_2, matches );
  
      double max_dist = 0; double min_dist = 100;
  
      //-- Quick calculation of max and min distances between keypoints
      for( int i = 0; i &lt; descriptors_1.rows; i++ )
      { 
          double dist = matches[i].distance;
          if( dist &lt; min_dist )
              min_dist = dist;
          if( dist &gt; max_dist )
              max_dist = dist;
      }
  
      printf("-- Max dist : %f \n", max_dist );
      printf("-- Min dist : %f \n", min_dist );
  
      //-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist )
      //-- PS.- radiusMatch can also be used here.
      std::vector&lt; DMatch &gt; good_matches;
      for( int i = 0; i &lt; descriptors_1.rows; i++ )
      { 
          if( matches[i].distance &lt; 3*min_dist )
          { 
              good_matches.push_back( matches[i]);
          }
      }
  
      //-- Draw only "good" matches
      Mat img_matches;
      drawMatches( img_1, keypoints_1, img_2, keypoints_2, good_matches, img_matches, \
          Scalar::all(-1), Scalar::all(-1),vector&lt;char&gt;(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
  
      //now I have two group keypoint,keypoints_1 and keypoints_2,and they is match.
      //keypoints_1 is tmeplate image`s keypoints,
      //keypoints_2 is source image`s keypoints,
      //so I how to compare distribution of keypoints_1 and keypoints_2?
      //if the two group keypoint`s distribute is very similarity,I will think the two image is match
  
      return 0;
  </code></pre>
  
  <p>}</p>
  
  <p>I use OpenCV2.4.9,VS 2010.</p>