Discussion:
Left-handed to right-handed
Jen Hunter
2011-10-24 11:57:14 UTC
Permalink
Hi,

I am currently working on a pose estimation combined with OpenSceneGraph rendering.
It seems that the POSIT algorithm from OpenCv needs modelpoints from a left handed coordinate system.
I am working with Sketchup exported Collada files that are right handed. OpenSceneGraph is as OpenGL right handed as well.

So I calculate the pose with the POSIT algorithm with left handed input 3D points and get a left handed pose.
When I apply a negative scaling along z and change the winding order to osg::FrontFace::CLOCKWISE it is displayed left-handed.

For various reasons I'd rather have it displayed right-handed as usual.

I was wondering if there is a way to transform a left-handed modelview matrix into a right-handed one?

I'd really appreciate any idea.

Thank you!
Dakota

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=43516#43516
Robert Osfield
2011-10-25 07:48:10 UTC
Permalink
Hi Dakota,
Post by Jen Hunter
I was wondering if there is a way to transform a left-handed modelview matrix into a right-handed one?
You just an osg::MatrixTransform above your subgraph that use
osg::Matrix::scale(sx,sy,sz) with the appropriate scale value. You
might also want to apply a rotation as well. I can't recommend
specifics in this case as I'm not familiar with the OpenCV coordinate
system and frame and what you want to achieve on the OSG side.

Robert.
Jen Hunter
2011-10-25 08:37:36 UTC
Permalink
Hi Robert,

thanks for your reply!

It was indeed a scaling and I had to switch the second and the third row of the rotation matrix. It looks like this:


Code:

viewMatrix.set(
rotation_matrix[0], rotation_matrix[3], rotation_matri[6], 0.0f,
rotation_matrix[2], rotation_matrix[5], rotation_matrix[8], 0.0f,
rotation_matrix[1], rotation_matrix[4], rotation_matrix[7], 0.0f,
translation_vector[0], translation_vector[1], translation_vector[2], 1.0f);

viewMatrix.postMultScale(osg::Vec3(1,1,-1));




However, I finally found out that OpenCv can also accept modelpoints from a right-handed coodinate system as well, when the given imagepoints are modified for that case.

With that I can use a matrix that looks like this:


Code:

viewMatrix.set(
rotation_matrix[0], rotation_matrix[3], rotation_matrix[6], 0.0f,
rotation_matrix[1], rotation_matrix[4], rotation_matrix[7], 0.0f,
rotation_matrix[2], rotation_matrix[5], rotation_matrix[8], 0.0f,
translation_vector[0], translation_vector[1], translation_vector[2], 1.0f);

viewMatrix.postMultScale(osg::Vec3(1,-1,-1));




I am not quite sure why I have to apply negative scaling at all, let alone to two axes because I would have guessed that with right-handed model and imagepoints I would get a correct right handed matrix that doesn't need any transformation. But it works that way and I'm happy about it. :)

I attached a picture of my test example.


Dakota

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=43536#43536

Loading...