Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

SVD on Android SDK

Hi, I am doing some Structure-from-Motion approach and having some trouble getting R and T from the essential matrix.

So far I am doing the following steps:

  • Calibrate Camera
  • Take two images with the same camera
  • undistort images
  • find feature points
  • match features
  • calculate fundamental matrix F using Mat fundamental = Calib3d.findFundamentalMat(object_left, object_right);
  • Calulate essential matix E using the following block of code:

    Mat E = new Mat();

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

    Core.multiply(E, cameraMatrix, E);


Using E I now need to calculate R and T, the relative rotation and translation between both cameras. I've read the chapter about SCV and E in Hartley and Zisserman, but now I am struggeling with OpenCV Code. A quick google-question brought me this code which is in C++:

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

The problem is now that I don't know how to transfer this code to Android/Java. There is no object SVD. I am doing the SVD for E using Mat svd = E.inv(Core.DECOMP_SVD); which returns a Mat Object.

Can someone help me please? I need access to U, W and VT from the singular value decomposition.

click to hide/show revision 2
retagged

updated 2014-03-28 06:25:45 -0600

berak gravatar image

SVD on Android SDK

Hi, I am doing some Structure-from-Motion approach and having some trouble getting R and T from the essential matrix.

So far I am doing the following steps:

  • Calibrate Camera
  • Take two images with the same camera
  • undistort images
  • find feature points
  • match features
  • calculate fundamental matrix F using Mat fundamental = Calib3d.findFundamentalMat(object_left, object_right);
  • Calulate essential matix E using the following block of code:

    Mat E = new Mat();

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

    Core.multiply(E, cameraMatrix, E);


Using E I now need to calculate R and T, the relative rotation and translation between both cameras. I've read the chapter about SCV and E in Hartley and Zisserman, but now I am struggeling with OpenCV Code. A quick google-question brought me this code which is in C++:

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

The problem is now that I don't know how to transfer this code to Android/Java. There is no object SVD. I am doing the SVD for E using Mat svd = E.inv(Core.DECOMP_SVD); which returns a Mat Object.

Can someone help me please? I need access to U, W and VT from the singular value decomposition.

click to hide/show revision 3
No.3 Revision

SVD on Android SDK

Hi, I am doing some Structure-from-Motion approach and having some trouble getting R and T from the essential matrix.

So far I am doing the following steps:

  • Calibrate Camera
  • Take two images with the same camera
  • undistort images
  • find feature points
  • match features
  • calculate fundamental matrix F using Mat fundamental = Calib3d.findFundamentalMat(object_left, object_right);
  • Calulate Calculate essential matix E using the following block of code:

     Mat E = new Mat();

    Mat(); Core.multiply(cameraMatrix.t(),fundamental, E);

    E); Core.multiply(E, cameraMatrix, E);


Using E I now need to calculate R and T, the relative rotation and translation between both cameras. I've read the chapter about SCV and E in Hartley and Zisserman, but now I am struggeling with OpenCV Code. A quick google-question brought me this code which is in C++:

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

The problem is now that I don't know how to transfer this code to Android/Java. There is no object SVD. I am doing the SVD for E using Mat svd = E.inv(Core.DECOMP_SVD); which returns a Mat Object.

Can someone help me please? I need access to U, W and VT from the singular value decomposition.