ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org

# rospy convert matrix to transform

How would I convert a 4x4 numpy matrix to (translation, quaternion) using tf (or some other package package) in python?

On the wiki for python tf, I found the method fromTranslationRotation, which converts (translation, quaternion) to numpy matrix. What's the method that does the inverse operation?

The context (though I'm not sure this is relevant) is to connect two tf trees.

/camera_1
/ar_marker_1

/camera_2
/ar_marker_2


I can't easily measure the transform between camera_1 and camera_2, so I've placed AR markers where I can easily measure the transform between them, and one camera can see each marker. I know the transform between ar_marker_1 and ar_marker_2, but tf trees have to be connected by the root, so I've used matrices to compute the transform from ar_marker_1 to camera_2, but now I can't figure out how to publish that transform because it's a matrix, not a (translation, quaternion).

edit retag close merge delete

Here's a related question in c++: http://answers.ros.org/question/10341...

( 2015-07-06 17:56:45 -0600 )edit

Sort by ยป oldest newest most voted

tf.transformations.decompose_matrix is able to get the translation, rotation and more from a matrix. Example usage:

    scale, shear, rpy_angles, translation_vector, perspective = \
tf.transformations.decompose_matrix(transformation_matrix)


The source code is here.

more