From a2fb282e7db992c25ff0dc2cfec148af390c08e1 Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Fri, 19 Jan 2024 11:06:30 -0500 Subject: [PATCH] image_view: consistent image_transport (#876) All of these nodes already have the proper remapping support - but image_transport parameter support was scattered --- image_view/src/extract_images_node.cpp | 6 ++++-- image_view/src/image_saver_node.cpp | 8 ++++++-- image_view/src/image_view_node.cpp | 7 ++++--- image_view/src/stereo_view_node.cpp | 9 +++++---- image_view/src/video_recorder_node.cpp | 8 +++++++- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/image_view/src/extract_images_node.cpp b/image_view/src/extract_images_node.cpp index bf6513a97..db572f8fb 100644 --- a/image_view/src/extract_images_node.cpp +++ b/image_view/src/extract_images_node.cpp @@ -75,13 +75,15 @@ ExtractImagesNode::ExtractImagesNode(const rclcpp::NodeOptions & options) auto node_base = this->get_node_base_interface(); std::string topic = node_base->resolve_topic_or_service_name("image", false); - this->declare_parameter("transport", std::string("raw")); + // TransportHints does not actually declare the parameter + this->declare_parameter("image_transport", "raw"); + image_transport::TransportHints hints(this); std::string transport = this->get_parameter("transport").as_string(); sub_ = image_transport::create_subscription( this, topic, std::bind( &ExtractImagesNode::image_cb, this, std::placeholders::_1), - transport); + hints.getTransport()); auto topics = this->get_topic_names_and_types(); diff --git a/image_view/src/image_saver_node.cpp b/image_view/src/image_saver_node.cpp index 9707f8a1b..f473e7aa2 100644 --- a/image_view/src/image_saver_node.cpp +++ b/image_view/src/image_saver_node.cpp @@ -71,6 +71,10 @@ namespace image_view ImageSaverNode::ImageSaverNode(const rclcpp::NodeOptions & options) : rclcpp::Node("image_saver_node", options) { + // TransportHints does not actually declare the parameter + this->declare_parameter("image_transport", "raw"); + image_transport::TransportHints hints(this); + // For compressed topics to remap appropriately, we need to pass a // fully expanded and remapped topic name to image_transport auto node_base = this->get_node_base_interface(); @@ -80,13 +84,13 @@ ImageSaverNode::ImageSaverNode(const rclcpp::NodeOptions & options) cam_sub_ = image_transport::create_camera_subscription( this, topic, std::bind( &ImageSaverNode::callbackWithCameraInfo, this, std::placeholders::_1, std::placeholders::_2), - "raw"); + hints.getTransport()); // Useful when CameraInfo is not being published image_sub_ = image_transport::create_subscription( this, topic, std::bind( &ImageSaverNode::callbackWithoutCameraInfo, this, std::placeholders::_1), - "raw"); + hints.getTransport()); std::string format_string; format_string = this->declare_parameter("filename_format", std::string("left%04i.%s")); diff --git a/image_view/src/image_view_node.cpp b/image_view/src/image_view_node.cpp index 5a4356e78..604745870 100644 --- a/image_view/src/image_view_node.cpp +++ b/image_view/src/image_view_node.cpp @@ -104,15 +104,16 @@ cv_bridge::CvImageConstPtr ThreadSafeImage::pop() ImageViewNode::ImageViewNode(const rclcpp::NodeOptions & options) : rclcpp::Node("image_view_node", options) { - auto transport = this->declare_parameter("image_transport", "raw"); - RCLCPP_INFO(this->get_logger(), "Using transport \"%s\"", transport.c_str()); + // TransportHints does not actually declare the parameter + this->declare_parameter("image_transport", "raw"); + image_transport::TransportHints hints(this); + RCLCPP_INFO(this->get_logger(), "Using transport \"%s\"", hints.getTransport().c_str()); // For compressed topics to remap appropriately, we need to pass a // fully expanded and remapped topic name to image_transport auto node_base = this->get_node_base_interface(); std::string topic = node_base->resolve_topic_or_service_name("image", false); - image_transport::TransportHints hints(this, transport); pub_ = this->create_publisher("output", 1); sub_ = image_transport::create_subscription( this, topic, std::bind( diff --git a/image_view/src/stereo_view_node.cpp b/image_view/src/stereo_view_node.cpp index 04c015e62..72b7bb56e 100644 --- a/image_view/src/stereo_view_node.cpp +++ b/image_view/src/stereo_view_node.cpp @@ -97,8 +97,9 @@ StereoViewNode::StereoViewNode(const rclcpp::NodeOptions & options) std::string format_string = this->get_parameter("filename_format").as_string(); filename_format_.parse(format_string); - this->declare_parameter("transport", std::string("raw")); - std::string transport = this->get_parameter("transport").as_string(); + // TransportHints does not actually declare the parameter + this->declare_parameter("image_transport", std::string("raw")); + image_transport::TransportHints hints(this); // Do GUI window setup int flags = autosize ? (cv::WINDOW_AUTOSIZE | cv::WINDOW_KEEPRATIO | cv::WINDOW_GUI_EXPANDED) : 0; @@ -126,8 +127,8 @@ StereoViewNode::StereoViewNode(const rclcpp::NodeOptions & options) stereo_ns + "/disparity", this->get_name(), this->get_namespace()); // Subscribe to three input topics. - left_sub_.subscribe(this, left_topic, transport); - right_sub_.subscribe(this, right_topic, transport); + left_sub_.subscribe(this, left_topic, hints.getTransport()); + right_sub_.subscribe(this, right_topic, hints.getTransport()); disparity_sub_.subscribe(this, disparity_topic); RCLCPP_INFO( diff --git a/image_view/src/video_recorder_node.cpp b/image_view/src/video_recorder_node.cpp index a11d211d9..10f672f16 100644 --- a/image_view/src/video_recorder_node.cpp +++ b/image_view/src/video_recorder_node.cpp @@ -66,13 +66,19 @@ VideoRecorderNode::VideoRecorderNode(const rclcpp::NodeOptions & options) rclcpp::shutdown(); } + // TransportHints does not actually declare the parameter + this->declare_parameter("image_transport", "raw"); + image_transport::TransportHints hints(this); + // For compressed topics to remap appropriately, we need to pass a // fully expanded and remapped topic name to image_transport auto node_base = this->get_node_base_interface(); std::string topic = node_base->resolve_topic_or_service_name("image", false); sub_image = image_transport::create_subscription( - this, topic, std::bind(&VideoRecorderNode::callback, this, std::placeholders::_1), "raw"); + this, topic, std::bind( + &VideoRecorderNode::callback, this, + std::placeholders::_1), hints.getTransport()); RCLCPP_INFO(this->get_logger(), "Waiting for topic %s...", topic.c_str()); }