Skip to content

Commit

Permalink
stereo_image_proc: disparity_node: Add parameter to control camera_in…
Browse files Browse the repository at this point in the history
…fo (#1051)

Add a parameter, use_image_transport_camera_info (default:
true), to control whether DisparityNode uses
image_transport::getCameraInfoTopic for deriving camera_info topics.

    Default Behavior (backward compatible):
When use_image_transport_camera_info is true, the node continues using
image_transport::getCameraInfoTopic for camera_info resolution,
maintaining existing functionality.

    Custom Behavior:
When use_image_transport_camera_info is false, the node directly uses
the camera_info topics specified via remapping (e.g., left/camera_info
and right/camera_info), bypassing image_transport's derivation logic.

This solution allows users to explicitly remap the camera_info topics
for both cameras, providing flexibility for scenarios where topic names
are not unique or need customization.

---------

Signed-off-by: Zhaoyuan Cheng <[email protected]>
Signed-off-by: Zhaoyuan <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
  • Loading branch information
quic-zhaoyuan and ahcorde authored Nov 28, 2024
1 parent a7283c7 commit bb4ab63
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions stereo_image_proc/doc/components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ Parameters
over the network than camera info and/or the delay from disparity processing
is too long.

*Common*
* **use_image_transport_camera_info** (bool, default: true): To control whether DisparityNode uses image_transport::getCameraInfoTopic for deriving camera_info topics. To set false, the node directly uses the camera_info topics specified via remapping (e.g., left/camera_info and right/camera_info), bypassing image_transport's derivation logic.

stereo_image_proc::PointCloudNode
---------------------------------
Combines a rectified color image and disparity image to produce a
Expand Down
23 changes: 17 additions & 6 deletions stereo_image_proc/src/stereo_image_proc/disparity_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class DisparityNode : public rclcpp::Node
SEMI_GLOBAL_BLOCK_MATCHING
};

bool use_image_transport_camera_info;
// Subscriptions
image_transport::SubscriberFilter sub_l_image_, sub_r_image_;
message_filters::Subscriber<sensor_msgs::msg::CameraInfo> sub_l_info_, sub_r_info_;
Expand Down Expand Up @@ -170,6 +171,8 @@ DisparityNode::DisparityNode(const rclcpp::NodeOptions & options)
bool approx = this->declare_parameter("approximate_sync", false);
double approx_sync_epsilon = this->declare_parameter("approximate_sync_tolerance_seconds", 0.0);
this->declare_parameter("use_system_default_qos", false);
use_image_transport_camera_info = this->declare_parameter("use_image_transport_camera_info",
true);

// Synchronize callbacks
if (approx) {
Expand Down Expand Up @@ -307,12 +310,20 @@ DisparityNode::DisparityNode(const rclcpp::NodeOptions & options)
std::string right_topic =
node_base->resolve_topic_or_service_name("right/image_rect", false);
// Allow also remapping camera_info to something different than default
std::string left_info_topic =
node_base->resolve_topic_or_service_name(
image_transport::getCameraInfoTopic(left_topic), false);
std::string right_info_topic =
node_base->resolve_topic_or_service_name(
image_transport::getCameraInfoTopic(right_topic), false);
std::string left_info_topic;
std::string right_info_topic;

if (use_image_transport_camera_info) {
// Use image_transport to derive camera_info topics
left_info_topic = node_base->resolve_topic_or_service_name(
image_transport::getCameraInfoTopic(left_topic), false);
right_info_topic = node_base->resolve_topic_or_service_name(
image_transport::getCameraInfoTopic(right_topic), false);
} else {
// Use default camera_info topics
left_info_topic = node_base->resolve_topic_or_service_name("left/camera_info", false);
right_info_topic = node_base->resolve_topic_or_service_name("right/camera_info", false);
}

// REP-2003 specifies that subscriber should be SensorDataQoS
const auto sensor_data_qos = rclcpp::SensorDataQoS();
Expand Down

0 comments on commit bb4ab63

Please sign in to comment.