C++ 将RANSAC应用于向量<;点2f>;相似变换

C++ 将RANSAC应用于向量<;点2f>;相似变换,c++,opencv,sift,ransac,C++,Opencv,Sift,Ransac,我在findHomography函数中使用了CV_RANSAC选项,但现在我想使用EstimaterialGidTransform。因此,我不能再使用CV_RANSAC 我想消除我的SIFT特征匹配数据的异常值,并应用转换。我如何才能做到这一点?这里有一个对我有效的解决方案: 使用SURF描述符和提取器获取特征点 使用FLANN matcher获得好的匹配 交叉检查所有匹配项。我是这样做的: std::vector<Point2f> valid_coords_1, valid_co

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


我想消除我的SIFT特征匹配数据的异常值,并应用转换。我如何才能做到这一点?

这里有一个对我有效的解决方案:

  • 使用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);
      }
    }
    
    std::向量有效坐标1,有效坐标2;
    std::vector有效匹配;
    //--显示检测到的匹配
    整数计数器;
    浮动res;
    对于(int i=0;i<(int)良好的_匹配。size();i++){
    计数器=0;
    对于(int j=0;j<(int)良好的_匹配。size();j++){
    如果(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);
    如果(abs(res)<(img_1.rows*0.004+3)){//必须调整此值
    计数器++;
    }
    //printf(“将良好点%d与%d匹配:%f\n”,i,j,res);
    }
    }
    /*printf(“--良好匹配[%d]关键点1:%d(%f,%f)--关键点2:%d(%f,%f)距离:%f\n”,i,良好匹配[i]。queryIdx,
    关键点_1[good_matches[i].queryIdx].pt.x,关键点_1[good_matches[i].queryIdx].pt.y,
    很好的匹配[i].trainIdx,
    关键点_2[good_matches[i].trainIdx].pt.x,关键点_2[good_matches[i].trainIdx].pt.y,
    良好的匹配[i]。距离)*/
    //printf(“点编号%d:有%d个有效匹配项\n”,i,计数器);
    如果(计数器>(良好匹配.size()/10)){
    有效匹配。向后推(良好匹配[i]);
    有效的\u坐标\u 1.向后推(关键点\u 1[good\u matches[i].queryIdx].pt);
    有效的\u坐标\u 2.向后推(关键点\u 2[良好匹配[i].trainIdx].pt);
    }
    }
    
    • 使用了转换函数

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

您有2D或3D变换吗?EstimaterialGidTransform函数假定变换是二维的。我曾经做过一个项目,在这个项目中,我使用了findHomography和SURF的EstimaterialGidTransform,但这是一个固定的距离和一个平面。你们能解释一下你们想要比较什么吗?我正在制作全景图,这样就可以通过2D变换将图像缝合到参考图像上。我使用findHomography以投影方式缝合它,但最后它会展开。因此我想使用similarity transform.THX!我会查出来的!我本来打算自己实施ransac,但这会有很大帮助!