Ask Your Question
0

SVD on Android SDK

asked 2014-03-28 06:12:30 -0500

glethien gravatar image

updated 2014-03-31 10:56:52 -0500

Andrey Pavlenko gravatar image

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);
  • Calculate 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.

edit retag flag offensive close merge delete

Comments

2

http://docs.opencv.org/java/org/opencv/core/Core.html#SVDecomp(org.opencv.core.Mat,%20org.opencv.core.Mat,%20org.opencv.core.Mat,%20org.opencv.core.Mat)

berak gravatar imageberak ( 2014-03-28 06:29:05 -0500 )edit

Thansk - That is excactly what I was looking for!

glethien gravatar imageglethien ( 2014-03-28 07:19:41 -0500 )edit

+1 for messing with HZ ;)

berak gravatar imageberak ( 2014-03-28 07:25:18 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-03-31 13:28:20 -0500

glethien gravatar image

I've found the misstake. This code is not doing the right matrix multiplication.

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

I changed this to

      Core.gemm(cameraMatrix.t(), fundamental, 1, cameraMatrix, 1, E);

which is now doing the right matrix multiplication. As far as I can get ir from the documentation, Core.multiply is doing the multiplication for each element. not the dot product of row*col.

edit flag offensive delete link more

Comments

1

oh, cool. the same gemm receipe will also apply to your other problem ;)

berak gravatar imageberak ( 2014-03-31 13:32:47 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-03-28 06:12:30 -0500

Seen: 890 times

Last updated: Mar 31 '14