aihot  2017-04-30 10:54:08  OpenCV |   查看评论   
  •   
  •   std::vector<KeyPoint> keypoints_1, keypoints_2;  
  •   
  •   detector.detect( img_1, keypoints_1 );  
  •   detector.detect( img_2, keypoints_2 );  
  •   
  •   //-- 步骤2:计算描述符(特征向量)
  •   SurfDescriptorExtractor extractor;  
  •   
  •   Mat descriptors_1, descriptors_2;  
  •   
  •   extractor.compute( img_1, keypoints_1, descriptors_1 );  
  •   extractor.compute( img_2, keypoints_2, descriptors_2 );  
  •   
  •   //-- 步骤3:使用强力匹配器匹配描述符向量
  •   BruteForceMatcher< L2<float> > matcher;  
  •   std::vector< DMatch > matches;  
  •   matcher.match( descriptors_1, descriptors_2, matches );  
  •   
  •   //-- 绘制比赛
  •   Mat img_matches;  
  •   drawMatches( img_1, keypoints_1, img_2, keypoints_2, matches, img_matches );   
  •   
  •   //-- 显示检测到的匹配
  •   imshow("Matches", img_matches );  
  •   
  •   waitKey(0);  
  •   
  •   return 0;  
  • }  
  •   
  • /** 
  •  * @function readme 
  •  */  
  • void readme()  
  • { std::cout << " Usage: ./SURF_descriptor <img1> <img2>" << std::endl; }  

  • 当然,进行强匹配的效果不够理想,这里再介绍一种FLANN特征匹配算法。前两步与上述代码相同,第三步利用FlannBasedMatcher类进行特征匹配,并只保留好的特征匹配点,代码如下:

    1. //-- 步骤3:使用FLANN匹配器匹配描述符向量
    2. FlannBasedMatcher matcher;  
    3. std::vector< DMatch > matches;  
    4. matcher.match( descriptors_1, descriptors_2, matches );  
    5.   
    6. double max_dist = 0; double min_dist = 100;  
    7.   
    8. //-- 快速计算关键点之间的最大和最小距离
     

    除特别注明外,本站所有文章均为 赢咖4注册 原创,转载请注明出处来自OpenCV学习笔记(九)——2维特征Feature2D

    留言与评论(共有 0 条评论)
       
    验证码:
    [lianlun]1[/lianlun]