Skip to content

Commit

Permalink
Use TF2 package for quaternion conversion (backport #1031) (#1041)
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. This change allows a
source build of the ROS 2 "perception" variant on Ubuntu 20.04 without a
custom source build of OpenCV.

Addresses issue
https://github.com/ros-perception/image_pipeline/issues/1030<hr>This is
an automatic backport of pull request #1031 done by
[Mergify](https://mergify.com).

Co-authored-by: Ted Steiner <[email protected]>
  • Loading branch information
mergify[bot] and tedsteiner authored Oct 31, 2024
1 parent b07a10a commit 67d192b
Show file tree
Hide file tree
Showing 2 changed files with 8 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
12 changes: 6 additions & 6 deletions image_proc/src/track_marker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#include <tf2/LinearMath/Quaternion.h>

#include <cstddef>
#include <functional>
#include <memory>
Expand All @@ -40,9 +42,9 @@
#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>

namespace image_proc
{
Expand Down Expand Up @@ -135,11 +137,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 67d192b

Please sign in to comment.