ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

tvec is pretty straightforward, it is a translation vector which can be used directly.

rvec describes a rotation about an axis in three dimensional space. It is simply a vector pointing in some direction in three dimensional space, and its length is equal to the angle of rotation around the vector.

angle axis vector

ROS expects orientations/rotations to be in quaternions, and there's an easier way to convert them to this format. Just use the tf.transformations.quaternion_about_axis function. All you need to do is find the magnitude of rvec, which you can do yourself manually, or just call cv2.norm(rvec). The function may return rvec as a numpy 1x3 ndarray, so access it as rvec[0].

from tf.transformations import quaternion_about_axis

...

tf_stamped.transform.translation.x = tvec[0][0]
tf_stamped.transform.translation.y = tvec[0][1]
tf_stamped.transform.translation.z = tvec[0][2]
angle = cv2.norm(r[0])  // or use euclidean distance of each element added
tf_stamped.transform.rotation = Quaternion(*quaternion_about_axis(angle, r[0]))

tvec is pretty straightforward, it is a translation vector which can be used directly.

rvec describes a rotation about an axis in three dimensional space. It is simply a vector pointing in some direction in three dimensional space, and its length is equal to the angle of rotation around the vector.

angle axis vector

ROS expects orientations/rotations to be in quaternions, and there's an easier way to convert them to this format. Just use the tf.transformations.quaternion_about_axis function. All you need to do is find the magnitude of rvec, which you can do yourself manually, or just call cv2.norm(rvec). The function to get the magnitude. You may return rvec have rvec as a numpy 1x3 ndarray, so access it as rvec[0].

from tf.transformations import quaternion_about_axis

...

tf_stamped.transform.translation.x = tvec[0][0]
tf_stamped.transform.translation.y = tvec[0][1]
tf_stamped.transform.translation.z = tvec[0][2]
angle = cv2.norm(r[0])  // or use euclidean distance of each element added
tf_stamped.transform.rotation = Quaternion(*quaternion_about_axis(angle, r[0]))