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);
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.
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)
Thansk - That is excactly what I was looking for!
+1 for messing with HZ ;)