C++ 使用RANSAC估计两组点之间的二维变换

C++ 使用RANSAC估计两组点之间的二维变换,c++,opencv,affinetransform,homography,ransac,C++,Opencv,Affinetransform,Homography,Ransac,据我所知,OpenCV使用RANSAC来解决findHomography的问题,并返回一些有用的参数,如同形图掩码 然而,如果我只想估计2D变换,这意味着一个仿射矩阵,有没有办法使用使用RANSAC并返回该掩码的findHomography的相同方法?在内部使用RANSAC,尽管参数目前是固定的-请参见此处的代码- cv::Mat cv::EstimaterialGidTransform(输入阵列src1、输入阵列src2、布尔全仿射) { 最大值=500; const int RANSAC_S

据我所知,OpenCV使用RANSAC来解决
findHomography
的问题,并返回一些有用的参数,如
同形图掩码

然而,如果我只想估计2D变换,这意味着一个仿射矩阵,有没有办法使用使用RANSAC并返回该掩码的
findHomography
的相同方法?

在内部使用RANSAC,尽管参数目前是固定的-请参见此处的代码-

cv::Mat cv::EstimaterialGidTransform(输入阵列src1、输入阵列src2、布尔全仿射)
{
最大值=500;
const int RANSAC_SIZE0=3;
常数双RANSAC_良好_比率=0.5;
// ...
//RANSAC材料:
//1.找到共识
对于(k=0;k
您可以直接使用estimateAffinePartial2D:

例如:

        src_pts = np.float32([pic1.key_points[m.queryIdx].pt for m in matches]).reshape(-1, 1, 2)
        dst_pts = np.float32([pic2.key_points[m.trainIdx].pt for m in matches]).reshape(-1, 1, 2)

        # Find the transformation between points, standard RANSAC
        transformation_matrix, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0)

        # Compute a rigid transformation (without depth, only scale + rotation + translation) and RANSAC
        transformation_rigid_matrix, rigid_mask = cv2.estimateAffinePartial2D(src_pts, dst_pts)

相关:提到使用似乎在内部使用RANSAC,如果你知道如何从3个点对计算2D变换,你可以很容易地编写你自己的简单RANSAC。好的,EstimaterialGidTransform使用RANSAC,但不幸的是你不能参数化它…好的,谢谢..所以没有现成的解决方案..代码在你复制后发生了变化-粘贴。它现在直接调用estimateAffinePartial2D。
cv::Mat cv::estimateAffinePartial2D (   
    InputArray  from,
    InputArray  to,
    OutputArray     inliers = noArray(),
    int     method = RANSAC,
    double  ransacReprojThreshold = 3,
    size_t  maxIters = 2000,
    double  confidence = 0.99,
    size_t  refineIters = 10 
)   
        src_pts = np.float32([pic1.key_points[m.queryIdx].pt for m in matches]).reshape(-1, 1, 2)
        dst_pts = np.float32([pic2.key_points[m.trainIdx].pt for m in matches]).reshape(-1, 1, 2)

        # Find the transformation between points, standard RANSAC
        transformation_matrix, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0)

        # Compute a rigid transformation (without depth, only scale + rotation + translation) and RANSAC
        transformation_rigid_matrix, rigid_mask = cv2.estimateAffinePartial2D(src_pts, dst_pts)