Ask Your Question
0

Decomposition of essential matrix leads to wrong rotation and translation

asked 2014-03-29 06:52:14 -0600

glethien gravatar image

updated 2014-03-29 07:04:16 -0600

berak gravatar image

Hi, I am doing some SfM and having troubles getting R and T from the essential matrix.

Here is what I am doing in sourcecode:

            Mat fundamental = Calib3d.findFundamentalMat(object_left, object_right);
    Mat E = new Mat();

    Core.multiply(cameraMatrix.t(), fundamental, E); // cameraMatrix.t()*fundamental*cameraMatrix;
    Core.multiply(E, cameraMatrix, E);

    Mat R = new Mat();
    Mat.zeros(3, 3, CvType.CV_64FC1).copyTo(R);

    Mat T = new Mat();

    calculateRT(E, R, T);

private void calculateRT(Mat E, Mat R, Mat T){

    /*
     * //-- Step 6: calculate Rotation Matrix and Translation Vector
        Matx34d P;
        //decompose E 
        SVD svd(E,SVD::MODIFY_A);
        Mat svd_u = svd.u;
        Mat svd_vt = svd.vt;
        Mat svd_w = svd.w;
        Matx33d W(0,-1,0,1,0,0,0,0,1);//HZ 9.13
        Mat_<double> R = svd_u * Mat(W) * svd_vt; //
        Mat_<double> T = svd_u.col(2); //u3

        if (!CheckCoherentRotation (R)) {
        std::cout<<"resulting rotation is not coherent\n";
        return 0;
        }

     */
    Mat w = new Mat();
    Mat u = new Mat();
    Mat vt = new Mat();

    Core.SVDecomp(E, w, u, vt, Core.DECOMP_SVD); // Maybe use flags
    double[] W_Values = {0,-1,0,1,0,0,0,0,1};
    Mat W = new Mat(new Size(3,3), CvType.CV_64FC1, new Scalar(W_Values) );

    Core.multiply(u, W, R);
    Core.multiply(R, vt, R);

    T = u.col(2);
}

And here are the results of all matrizes after and during calculation.

        Number matches: 10299
        Number of good matches: 590
        Number of obj_points left: 590.0

        Fundamental: 
        [4.209958176688844e-08, -8.477216249742946e-08, 9.132798068178793e-05;
        3.165719895008366e-07, 6.437858397735847e-07, -0.0006976204595236443;
        0.0004532506630569588, -0.0009224427024602799, 1]

        Essential: 
        [0.05410018455525099, 0, 0;
        0, 0.8272987826496967, 0;
        0, 0, 1]

        U: 
        [0, 0, 1;
         0, 0.9999999999999999, 0;
         1, 0, 0]

        W: 
        [1; 0.8272987826496967; 0.05410018455525099]

        vt:
        [0, 0, 1;
         0, 1, 0;
         1, 0, 0]


        R: 
        [0, 0, 0;
         0, 0, 0;
         0, 0, 0]

        T: 
        [1; 0; 0]

And for completion here are the image I am using left: https://drive.google.com/file/d/0Bx9OKnxaua8kXzRFNFRtMlRHSzg/edit?usp=sharing right: https://drive.google.com/file/d/0Bx9OKnxaua8kd3hyMjN1Zll6ZkE/edit?usp=sharing

Can someone point out where something is goind wrong or what I am doing wrong?

edit retag flag offensive close merge delete

Comments

Core.gemm(u, W, 1, vt, 1, R);

instead of:

Core.multiply(u, W, R);
Core.multiply(R, vt, R);
berak gravatar imageberak ( 2014-03-31 13:36:36 -0600 )edit

1 answer

Sort by » oldest newest most voted
2

answered 2014-03-29 07:54:55 -0600

berak gravatar image

updated 2014-03-29 08:42:43 -0600

imho, your initialization for W fails here:

    Mat W = new Mat(new Size(3,3), CvType.CV_64FC1, new Scalar(W_Values) );

a Scalar is more like a 'pixel', so since we have a 1channel mat, it took only the 1st element of the array supplied.

better, put() the array:

    Mat W = new Mat(new Size(3,3), CvType.CV_64FC1 );
    double[] W_Values = {0,-1,0,1,0,0,0,0,1};
    W.put(0, 0, W_Values);
    System.out.println(W.dump());

[0, -1, 0;
 1, 0, 0;
 0, 0, 1]
edit flag offensive delete link more

Comments

Thanks soo much!!!!

glethien gravatar imageglethien ( 2014-03-29 08:19:17 -0600 )edit

sorry, confused E and F above.

so, result unchanged, :(

berak gravatar imageberak ( 2014-03-29 08:30:57 -0600 )edit

Could it be possible that my fundamental matrix is equals to the essential matrix as Hartley and Zissermann states:

„11.7.3 The calibrated case

In the case of calibrated cameras normalized image coordinates may be used, and the essential matrix E computed instead of the fundamental matrix”

glethien gravatar imageglethien ( 2014-03-31 04:36:53 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-03-29 06:52:14 -0600

Seen: 3,268 times

Last updated: Mar 29 '14