无法在两个图像之间执行角点匹配

时间:2017-07-24 10:36:52

标签: opencv feature-detection surf template-matching

我正在使用openCV 2.4,我正在使用FlannBasedMatcher来匹配关键点。但是,我没有使用SurfFeatureDetector::detect()来提取关键点,而是将图像角点作为关键点传递。

可悲的是,我为minHessian的所有值获得了零匹配。

以下是我的代码:

void matches(int, void*)

{


SurfFeatureDetector detector( minHessian );

vector<KeyPoint> keypoints_frame,keypoints_trng;
Mat descriptors_frame,descriptors_trng;
//detect keypoints



for(int i=0;i<corners.size();i++)
    {
      keypoints_frame.push_back(KeyPoint(corners[i].x,corners[i].y,0));
    cout<<"\n"<<keypoints_frame[i].pt.x<<"\t"<<keypoints_frame[i].pt.y;
    }
keypoints_trng.push_back(KeyPoint(337,288,0));
keypoints_trng.push_back(KeyPoint(337,241,0));
keypoints_trng.push_back(KeyPoint(370,288,0));
keypoints_trng.push_back(KeyPoint(370,241,0));
keypoints_trng.push_back(KeyPoint(291,239,0));
keypoints_trng.push_back(KeyPoint(287,203,0));
keypoints_trng.push_back(KeyPoint(288,329,0));
keypoints_trng.push_back(KeyPoint(426,237,0));
keypoints_trng.push_back(KeyPoint(428,326,0));
keypoints_trng.push_back(KeyPoint(426,201,0));
keypoints_trng.push_back(KeyPoint(427,293,0));
keypoints_trng.push_back(KeyPoint(287,297,0));

for(int i=0;i<corners.size();i++)
    {

    cout<<"\n"<<keypoints_trng[i].pt.x<<"\t"<<keypoints_trng[i].pt.y;
    }
//describe keypoints

SurfDescriptorExtractor extractor;
extractor.compute( src_gray_resized, keypoints_frame, descriptors_frame);
extractor.compute( trng_gray_resized, keypoints_trng, descriptors_trng);

//matching the keypoints
  FlannBasedMatcher matcher;
  std::vector< DMatch > matches;
  matcher.match( descriptors_frame, descriptors_trng, matches );
cout<<"\n\n no of matches: "<<matches.size();
std::vector< DMatch > good_matches;
if (matches.size()>20)
{minHessian=minHessian+100;}


  for( int i = 0; i < descriptors_frame.rows; i++ )
  { if( matches[i].distance <= max(2*100.00, 0.02) )
            { good_matches.push_back( matches[i]); }
  }
//cout<<"\nno of good matches"<<good_matches.size();
  //-- Draw only "good" matches
  Mat img_matches;
  drawMatches( src_gray, keypoints_frame, trng_gray, keypoints_trng,
               good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
               vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );

  //-- Show detected matches
namedWindow("Good Matches",CV_WINDOW_NORMAL);
  imshow( "Good Matches", img_matches );

}

0 个答案:

没有答案