从Homography分解中寻找最合适的旋转和平移

问题描述 投票:2回答:2

我正试图从Homography功能中找到旋转和平移。首先,我计算相应的特征点,并使用findHomography()我计算了Homography矩阵。然后,使用decomposeHomographyMat(),我得到了四个旋转和翻译结果。

我使用的代码如下:

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);

现在什么是正确的轮换和翻译,至少是最合适的。我甚至使用下面的函数检查旋转是否有效,并发现所有都有效。

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;
}

请有人建议我,我应该使用什么价值。结果转换是一个缩放值,可以直接使用,与Essential Matrix分解情况不同?我非常感谢有人能指导我找到这个。

感谢您!

opencv computer-vision homography multiview
2个回答
2
投票

我使用了Vaesper的函数'filterHomographyDecompByVisibleRefpoints'。你可以检查代码here

您只需要输入旋转矩阵,从decomposeHomographyMat获得的法线和用于获得单应矩阵的点对应关系。上述功能将返回2种可能的解决方案。你可以在Ebya here的回答中看到更多关于这个想法的内容。

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


2
投票

结果转换是一个缩放值,可以直接使用,与Essential Matrix分解情况不同?

唉,没有。

OpenCV实现的参考文献Malis&Vargas在第8页说明了这一点:

请注意,转换估计最多为正标量因子

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.