Skip to content

Instantly share code, notes, and snippets.

@Veilkrand
Created February 19, 2019 12:49
Show Gist options
  • Save Veilkrand/63e9885ebd9f128477951033b610a313 to your computer and use it in GitHub Desktop.
Save Veilkrand/63e9885ebd9f128477951033b610a313 to your computer and use it in GitHub Desktop.
Opencv To ROS TF
tf::Transform
ArucoMapping::arucoMarker2Tf(const aruco::Marker &marker)
{
cv::Mat marker_rotation(3,3, CV_32FC1);
cv::Rodrigues(marker.Rvec, marker_rotation);
cv::Mat marker_translation = marker.Tvec;
cv::Mat rotate_to_ros(3,3,CV_32FC1);
rotate_to_ros.at<float>(0,0) = -1.0;
rotate_to_ros.at<float>(0,1) = 0;
rotate_to_ros.at<float>(0,2) = 0;
rotate_to_ros.at<float>(1,0) = 0;
rotate_to_ros.at<float>(1,1) = 0;
rotate_to_ros.at<float>(1,2) = 1.0;
rotate_to_ros.at<float>(2,0) = 0.0;
rotate_to_ros.at<float>(2,1) = 1.0;
rotate_to_ros.at<float>(2,2) = 0.0;
marker_rotation = marker_rotation * rotate_to_ros.t();
// Origin solution
tf::Matrix3x3 marker_tf_rot(marker_rotation.at<float>(0,0),marker_rotation.at<float>(0,1),marker_rotation.at<float>(0,2),
marker_rotation.at<float>(1,0),marker_rotation.at<float>(1,1),marker_rotation.at<float>(1,2),
marker_rotation.at<float>(2,0),marker_rotation.at<float>(2,1),marker_rotation.at<float>(2,2));
tf::Vector3 marker_tf_tran(marker_translation.at<float>(0,0),
marker_translation.at<float>(1,0),
marker_translation.at<float>(2,0));
return tf::Transform(marker_tf_rot, marker_tf_tran);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment