c++ - 将 RANSAC 应用于 vector<Point2f> 以进行相似性变换

标签 c++ opencv sift ransac

我在 findHomography 函数中使用了 CV_RANSAC 选项,但现在我想使用 estimateRigidTransform。因此我不能再使用 CV_RANSAC。

我想消除我的 SIFT 特征匹配数据的异常值并应用 estimateRigidTransform。我该怎么做?

最佳答案

这是一个对我有用的解决方案:

  • 使用 SURF 描述符和提取器获取特征点
  • 使用 FLANN-matcher 获得良好的匹配
  • 交叉检查所有匹配项。这是我的做法:

    std::vector<Point2f> valid_coords_1, valid_coords_2;
    std::vector< DMatch > valid_matches;
    //-- Show detected matches
    
    
    int counter;
    float res;
    for( int i = 0; i < (int)good_matches.size(); i++ ){
      counter = 0;
      for(int j = 0; j < (int)good_matches.size(); j++){
        if(i!=j){
          res = cv::norm(keypoints_1[good_matches[i].queryIdx].pt - keypoints_1[good_matches[j].queryIdx].pt) - cv::norm(keypoints_2[good_matches[i].trainIdx].pt-keypoints_2[good_matches[j].trainIdx].pt);
          if(abs(res) < (img_1.rows * 0.004 + 3)){ //this value has to be adjusted
            counter++;
          }
          //printf("Match good point %d with %d: %f \n", i, j, res);
        }
      }
     /* printf( "-- Good Match [%d] Keypoint 1: %d (%f,%f)  -- Keypoint 2: %d (%f,%f) Distance: %f  \n", i, good_matches[i].queryIdx, 
        keypoints_1[good_matches[i].queryIdx].pt.x, keypoints_1[good_matches[i].queryIdx].pt.y, 
        good_matches[i].trainIdx, 
        keypoints_2[good_matches[i].trainIdx].pt.x, keypoints_2[good_matches[i].trainIdx].pt.y, 
        good_matches[i].distance); */
      //printf("Point nr %d: has %d valid matches \n", i, counter);
      if(counter > (good_matches.size() / 10)){
        valid_matches.push_back(good_matches[i]);
        valid_coords_1.push_back(keypoints_1[good_matches[i].queryIdx].pt);
        valid_coords_2.push_back(keypoints_2[good_matches[i].trainIdx].pt);
      }
    }
    
    • 使用了 estimateRigidTransform 函数。

我希望这在某种程度上有所帮助。如果您需要更多信息,请告诉我:)

关于c++ - 将 RANSAC 应用于 vector<Point2f> 以进行相似性变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25262507/

相关文章:

C++ 正则表达式 : replace\d\s( with\d*(

image-processing - 在opencv中查找轮廓的长度

cluster-analysis - SIFT 向量的分层 k 均值聚类

c++ - 带有ORB描述符的opencv FLANN?

c++ - 我可以使用 DuplicateHandle 来使用外部进程的句柄吗?

c++ - 如何使用 C++ 将时区化的 XML 类型 dateTime 转换为 time_t

c++ - 具有友元函数的模板类的链接器错误

c++ - OpenCV:如何创建多边形的 mask ?

c++ - 通过 warpAffine(opencv,c++)在旋转图像后获取 cv::rect 的新位置

python - 类型 'KeyPoint'的对象不是JSON可序列化的opencv