source http://answers.ros.org/question/37609/counterpart-to-pcl_rostransformasmatrix/
Counterpart to pcl_ros::transformAsMatrix ?
asked Jul 2 '12
This post is a wiki. Anyone with karma >75 is welcome to improve it.
Hi,
I understand pcl_ros::transformAsMatrix(const tf::Transform& bt, Eigen::Matrix4f &out_mat) can be used to convert a tf::transform to a 4x4 matrix describing the same transformation.
I am now looking for a method that does the same thing backwards, converting a 4x4 matrix to a tf::transform.
Is such a method already implemented somewhere?
Thanks
EDIT: Solution that works for me, thanks to Eric:
Eigen::Matrix4f mf; //The matrix I want to convert
Eigen::Matrix4d md(mf.cast ());
Eigen::Affine3d affine(md);
tf::Transform transform;
tf::TransformEigenToTF(affine, transform);
Comments
1
A small info which might be helpful for others. For ROS hydro, tf::transformEigenToTF must be used.
balakumar-s (Dec 1 '13)
add a comment
1 answer
answered Jul 2 '12
You should look at the tf_conversions package, specifically thetf::TransformEigenToTF function.
You would have to make an
Eigen::Affine3d
from your Eigen::Matrix4f
. See the Eigen Geometry Module Tutorial (and linked docs for each class) for information on how to go about that. I expect it involves a conversion from Matrix4f to Matrix4d and then passing that to the Affine3d constructor, but I don't know the exact function calls and syntax required off the top of my head.