aihot  2017-04-30 10:54:08  OpenCV |   查看评论   
  • forint i = 0; i < descriptors_1.rows; i++ )  
  • double dist = matches[i].distance;  
  •   if( dist < min_dist ) min_dist = dist;  
  •   if( dist > max_dist ) max_dist = dist;  
  • }  
  •   
  • printf("-- Max dist : %f \n", max_dist );  
  • printf("-- Min dist : %f \n", min_dist );  
  •   
  • //-- 仅绘制“好”匹配(即距离小于2 * min_dist)
  • //-- 也可以在这里使用PS.- radiusMatch。
  • std::vector< DMatch > good_matches;  
  •   
  • forint i = 0; i < descriptors_1.rows; i++ )  
  • if( matches[i].distance < 2*min_dist )  
  •   { good_matches.push_back( matches[i]); }  
  • }    
  •   
  • //-- 只画“好”的比赛
  • Mat img_matches;  
  • drawMatches( img_1, keypoints_1, img_2, keypoints_2,   
  •              good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),   
  •              vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );   
  •   
  • //-- 显示检测到的匹配
  • imshow( "Good Matches", img_matches );  

  • 在FLANN特征匹配的基础上,还可以进一步利用Homography映射找出已知物体。具体来说就是利用findHomography函数利用匹配的关键点找出相应的变换,再利用perspectiveTransform函数映射点群。具体代码如下:

    1. //-- 本地化对象 img_1 in img_2   
    2. std::vector<Point2f> obj;  
    3. std::vector<Point2f> scene;  
    4.   
    5. forint i = 0; i < good_matches.size(); i++ )  
    6. {  
    7.   //-- 从好的比赛中获取关键点
    8.   obj.push_back( keypoints_1[ good_matches[i].queryIdx ].pt );  
    9.   scene.push_back( keypoints_2[ good_matches[i].trainIdx ].pt );   
    10. }  
    11.   
    12. Mat H = findHomography( obj, scene, CV_RANSAC );  
     

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

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