Rodrigues giving empty Matrix

asked 2016-02-25 09:28:12 -0600

eqnx gravatar image

updated 2016-02-25 09:50:06 -0600


I'm implementing markerbased tracking on Android and I'm stuck at the rotation matrix.

Up until the solvePnP everything works fine and I get results (rvec, tvec) that seem legit. But after using the rvec in Rodrigues for having a rotation matrix, it just results in a 3x3 Matrix, filled only with zeroes.

I really don't get this, because there are definitely values in rvec, but Rodrigues just doesn't use them?

I hope somebody knows whats wrong.

Heres the code snippet:

Mat rvec = new Mat(3,1,CvType.CV_64F);
Mat tvec = new Mat(3,1,CvType.CV_64F);

MatOfPoint3f markerPointsMat = new MatOfPoint3f(new Point3(0,0,0),new Point3(1,0,0),new Point3(1,1,0),new Point3(0,1,0));

MatOfPoint2f pointsMat = new  MatOfPoint2f(points.get(0),points.get(1),points.get(2),points.get(3));

//cam matrix, by hand
    Mat cam=new Mat(3,3,CvType.CV_64F);

    cam.put(0, 0, 1400.533595140377 );
    cam.put(0, 2, 175.5 );
    cam.put(1, 1, 1400.533595140377 );
    cam.put(1, 2, 143.5);

    double[] a = {0.1155606860709641,-0.3046292381782507,0,0,0};
    MatOfDouble dist = new MatOfDouble(a);

Calib3d.solvePnP(markerPointsMat, pointsMat, cam, dist, rvec, tvec);

//rot vector to matrix
Mat rmat = Mat.zeros(3,3,CvType.CV_64F);
Rodrigues(rvec, rmat);
edit retag flag offensive close merge delete


btw, Mat.zeros()returns a new Matrix, so your (1st) call is redundant, and some fields in your cam Mat never get properly initialized. rather make a double[] with the values, like you did for the dist Mat

berak gravatar imageberak ( 2016-02-25 11:59:51 -0600 )edit