从单应性分解中找到最合适的旋转和平移 [英] Finding most suitable Rotation and Translation from Homography decomposition

查看:49
本文介绍了从单应性分解中找到最合适的旋转和平移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Homography 函数中找到旋转和平移.首先我计算相应的特征点并使用 findHomography() 我计算了 Homography Matrix.然后,使用 decomposeHomographyMat(),我得到了四个旋转和平移结果.

I'm trying to find the rotation and translation from Homography function. First I compute the corresponding feature points and using findHomography() I computed the Homography Matrix. Then, using decomposeHomographyMat(), I got four rotation and translations results.

我使用的代码如下:

Mat frame_1, frame_2;


frame_1 = imread("img1.jpg", IMREAD_GRAYSCALE);
frame_2 = imread("img2.jpg", IMREAD_GRAYSCALE);

vector<KeyPoint> keypts_1, keypts_2;
Mat desc1, desc2;

Ptr<Feature2D> ORB = ORB::create(100    );
ORB->detectAndCompute(frame_1, noArray(), keypts_1, desc1);
ORB->detectAndCompute(frame_2, noArray(), keypts_2, desc2);

Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce-Hamming");
vector<DMatch> matches;
matcher->match(desc1, desc2, matches);

vector<Point2f>leftPts, rightPts;
    for (size_t i = 0; i < matches.size(); i++)
    {
        //queryIdx is the left Image
        leftPts.push_back(keypts_1[matches[i].queryIdx].pt);

        //trainIdx is the right Image
        rightPts.push_back(keypts_2[matches[i].trainIdx].pt);
    }

Mat cameraMatrix = (Mat1d(3, 3) << 706.4034, 0, 277.2018, 0, 707.9991, 250.6182, 0, 0, 1);
Mat H = findHomography(leftPts, rightPts);
vector<Mat> R, t, n;
decomposeHomographyMat(H, cameraMatrix, R, t, n);

现在什么是正确的旋转和平移,至少是最合适的.我什至使用下面的函数检查了旋转是否有效,发现都是有效的.

Now what is the right rotation and translation, at least the most suitable. I even checked if the rotation is valid using the below function, and found all are valid.

bool isRotationMatrix(Mat &R)
{
    Mat Rt;
    transpose(R, Rt);
    Mat shouldBeIdentity = Rt * R;
    Mat I = Mat::eye(3, 3, shouldBeIdentity.type());

    return  norm(I, shouldBeIdentity) < 1e-6;
}

请有人建议我,我应该使用什么值.与基本矩阵分解情况不同,得到的翻译是一个可以直接使用的缩放值吗?如果有人能指导我找到这个,我非常感激.

Please some one suggest me, what value should I use. And is the resultant translation is a scaled value, which can be used directly, unlike the Essential Matrix decomposition case? I highly appreciate if someone can guide me on finding this.

谢谢你!

推荐答案

我使用了 Vaesper 的 'filterHomographyDecompByVisibleRefpoints' 函数.您可以查看代码这里.

I used the function 'filterHomographyDecompByVisibleRefpoints' by Vaesper. You can check the code here.

您只需要输入旋转矩阵、从 decomposeHomographyMat 获得的法线以及用于获得单应矩阵的点对应关系.上述函数将返回 2 个可能的解决方案.您可以在 Ebya 这里的回答中看到更多关于这个想法的信息.

You just need to input the Rotation matrix, normals obtained from decomposeHomographyMat and the point correspondences used to obtain the homograpy matrix. The above function will return 2 possible solutions. You can see more on this idea in the answer by Ebya here.

在获得 2 种可能的解决方案后,您必须根据自己的情况进行一些检查,以便找到正确的解决方案.由于我使用单位矩阵作为相机矩阵,因此获得的平移值以像素为单位,需要使用一些外部传感器进行缩放.在我的例子中,相机和平面物体之间的距离在 z 轴上是固定的,因此,我只是计算了 1 个像素在世界单位中代表什么.

After getting the 2 possible solutions, you will have to somehow make some checks depending on your case in order to find the right solution. Since I used identity matrix for camera matrix, the translation values obtained are in pixels and will need to be scaled using some external sensor. In my case, the distance between the camera and planar object is fixed in the z-axis, therefore, I just calculated what 1 pixel represents in world units.

这篇关于从单应性分解中找到最合适的旋转和平移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆