Skip to content

Commit

Permalink
Use TF2 package for quaternion conversion
Browse files Browse the repository at this point in the history
The OpenCV quaternion class was not added until OpenCV 4.5.1, so it's less widely available than the TF2 conversion.
  • Loading branch information
tedsteiner committed Sep 6, 2024
1 parent dbf697d commit 0030084
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions image_proc/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<depend>rclcpp_components</depend>
<depend>rcutils</depend>
<depend>sensor_msgs</depend>
<depend>tf2</depend>
<depend>tf2_geometry_msgs</depend>
<depend>tracetools_image_pipeline</depend>

<test_depend>ament_lint_auto</test_depend>
Expand Down
11 changes: 5 additions & 6 deletions image_proc/src/track_marker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@
#include <image_proc/track_marker.hpp>
#include <image_proc/utils.hpp>
#include <image_transport/image_transport.hpp>
#include <opencv2/core/quaternion.hpp>
#include <rclcpp/qos.hpp>
#include <rclcpp/rclcpp.hpp>
#include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
#include <tf2/LinearMath/Quaternion.h>

namespace image_proc
{
Expand Down Expand Up @@ -135,11 +136,9 @@ void TrackMarkerNode::imageCb(
pose.pose.position.y = tvecs[0][1];
pose.pose.position.z = tvecs[0][2];
// Convert angle-axis to quaternion
cv::Quatd q = cv::Quatd::createFromRvec(rvecs[0]);
pose.pose.orientation.x = q.x;
pose.pose.orientation.y = q.y;
pose.pose.orientation.z = q.z;
pose.pose.orientation.w = q.w;
const tf2::Vector3 rvec(rvecs[0][0], rvecs[0][1], rvecs[0][2]);
const tf2::Quaternion q(rvec.normalized(), rvec.length());
tf2::convert(q, pose.pose.orientation);
pub_->publish(pose);
}
}
Expand Down

0 comments on commit 0030084

Please sign in to comment.