Search for the most suitable rotation and translation from the decomposition of homography

I am trying to find the rotation and translation from the Homography function. First, I calculate the corresponding points of the function and using findHomography(), I calculated the homography matrix. Then, using decomposeHomographyMat(), I got four results of rotation and translation.

The code I used below:

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 turn and translation, at least the most suitable. I even checked if the rotation is valid using the function below and they are all 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;
}

, - , . , , Essential Matrix? , - .

!

+2
2

"filterHomographyDecompByVisibleRefpoints" Vaesper. .

, , HomographyMat, , . 2 . Ebya .

- , . , - . z, , 1 .

+3

, , Essential Matrix?

, .

OpenCV, , .8:

,

+2

Source: https://habr.com/ru/post/1583885/


All Articles