Aruco markers with openCv, get the 3d corner coordinates?

I am detecting a printed Aruco marker using opencv 3.2:

aruco::estimatePoseSingleMarkers(corners, markerLength, camMatrix, distCoeffs, rvecs,tvecs);


this returns a translation and rotation vector for the marker. What I need, is the 3d coordinates for each corner of the marker.

As i know the marker length, i could do something like

corner1 = tvecs[0] - markerlength /2;
corner2 = tvecs[0] + markerlength /2;
....


But is there an better way? Or an existing function?

How can i return the 3d corner coordinates of a marker, in world space (where the camera is at 0,0,0)?

Thanks!

edit retag close merge delete

Sort by ยป oldest newest most voted

So the way that function works, you pass in the location of the four corners in the image, and the marker length. It assumes the first corner is (0,0,0), and then the others are (ml, 0, 0), (0, ml, 0)...

The output is rvec and tvec, which gives you the orientation of the camera relative to the marker. Since you want the orientation of the marker relative to the camera, you need to invert those values.

Mat R;
Rodrigues(rvec, R);
R = R.t();
tvec = -R*tvec;
Rodrigues(R, rvec);


Then you can take the 3d values of the points (0,0,0), (ml, 0, 0) ... and transform them with rvec and tvec. You'll have to make the values yourself, so recommend looking at the code of estimatePoseSingleMarkers to make sure you've got the same values, or your results will be wrong.

Mat R;
Rodrigues(rvec, R);
3dpoint = R*point+tvec

more