Ask Your Question

marker to gl-matrix via OpenCV.js

asked 2018-11-14 16:30:02 -0600

dakom gravatar image

updated 2018-11-15 03:06:53 -0600

Let's assume we get rvecs and tvecs via cv.estimatePoseSingleMarkers()

Then going through each marker, we can get the 1x3 vectors like this (found in online samples):

const rotation = [rvecs.doublePtr(0, i)[0], rvecs.doublePtr(0, i)[1], rvecs.doublePtr(0, i)[2]];
const translation = [tvecs.doublePtr(0, i)[0], tvecs.doublePtr(0, i)[1], tvecs.doublePtr(0, i)[2]];

How can this be converted so it's compatible with gl-matrix's fromRotationTranslation?

Specifically - it seems gl-matrix expects the rotation in a quaternion... I see some sample C++ code to do that conversion here, but it assumes a Rodrigues function in OpenCV to get from the 1x3 vector to a 3x3 rotation matrix - I think?

The Rodrigues function seems to be missing in OpenCV.js... and it's not clear to me what exactly cv.estimatePoseSingleMarkers() is returning in each rvec (is it euler radians? something else?)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-11-15 00:57:50 -0600

berak gravatar image

updated 2018-11-15 01:16:49 -0600

you can construct a quat directly from the rvec, using fromEuler(), see here:

edit flag offensive delete link more


is a Rodrigues vector the same as Euler? If so - why is it called "Rodrigues" ? (wanted to upvote your answer in the meantime - but don't have enough karma yet :)

dakom gravatar imagedakom ( 2018-11-15 02:34:55 -0600 )edit

no, Rodrigues makes a 3x3 rotation Mat from a 1x3 vector, or the other way round, and it's named after it's inventor ;) (while fromEuler() makes a quat from a rotation vector)

wanted to upvote

kind of you, but i really don't need more karma here, heeh ;)

berak gravatar imageberak ( 2018-11-15 02:38:15 -0600 )edit

Cool! So the vector I get from cv.estimatePoseSingleMarkers() is in euler radians?

dakom gravatar imagedakom ( 2018-11-15 02:42:17 -0600 )edit

good point, but sorry, idk (never used aruco)

berak gravatar imageberak ( 2018-11-15 03:01:52 -0600 )edit

oh but that's the question. edited to make that clearer

dakom gravatar imagedakom ( 2018-11-15 03:06:01 -0600 )edit

well, it can only be rad or deg. fromEuler() expects degrees (and internally converts to radians)

maybe you have to print out some measurements. if you see any number larger than +-pi, then you know it's deg ;)

berak gravatar imageberak ( 2018-11-15 03:11:14 -0600 )edit

ah okay - I thought maybe there's some other possibility like the 3 values being something other than Euler. The docs on estimatePoseSingleMarkers aren't very clear - it simply says "see Rodrigues" o_O. I'll play around with it later and see what happens. Thanks!

dakom gravatar imagedakom ( 2018-11-15 03:30:51 -0600 )edit

Question Tools

1 follower


Asked: 2018-11-14 16:30:02 -0600

Seen: 396 times

Last updated: Nov 15 '18