diff --git a/compressed_image_transport/src/compressed_subscriber.cpp b/compressed_image_transport/src/compressed_subscriber.cpp index 28a1077..3733805 100644 --- a/compressed_image_transport/src/compressed_subscriber.cpp +++ b/compressed_image_transport/src/compressed_subscriber.cpp @@ -45,6 +45,7 @@ #include #include +#include constexpr const char* kDefaultMode = "unchanged"; @@ -67,24 +68,31 @@ void CompressedSubscriber::subscribeImpl( typedef image_transport::SimpleSubscriberPlugin Base; Base::subscribeImpl(node, base_topic, callback, custom_qos); std::string mode; - rcl_interfaces::msg::ParameterDescriptor mode_description; - mode_description.name = "mode"; - mode_description.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING; - mode_description.description = "OpenCV imdecode flags to use"; - mode_description.read_only = false; - mode_description.additional_constraints = "Supported values: [unchanged, gray, color]"; - mode = node->declare_parameter("mode", kDefaultMode, mode_description); - - if (mode == "unchanged") { - config_.imdecode_flag = cv::IMREAD_UNCHANGED; - } else if (mode == "gray") { - config_.imdecode_flag = cv::IMREAD_GRAYSCALE; - } else if (mode == "color") { - config_.imdecode_flag = cv::IMREAD_COLOR; - } else { - RCLCPP_ERROR(logger_, "Unknown mode: %s, defaulting to 'unchanged", mode.c_str()); - config_.imdecode_flag = cv::IMREAD_UNCHANGED; + uint ns_len = node->get_effective_namespace().length(); + std::string param_base_name = base_topic.substr(ns_len); + std::replace(param_base_name.begin(), param_base_name.end(), '/', '.'); + std::string mode_param_name = param_base_name + ".mode"; + if (!node->has_parameter(mode_param_name)) + { + rcl_interfaces::msg::ParameterDescriptor mode_description; + mode_description.name = "mode"; + mode_description.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING; + mode_description.description = "OpenCV imdecode flags to use"; + mode_description.read_only = false; + mode_description.additional_constraints = "Supported values: [unchanged, gray, color]"; + mode = node->declare_parameter(mode_param_name, kDefaultMode, mode_description); + if (mode == "unchanged") { + config_.imdecode_flag = cv::IMREAD_UNCHANGED; + } else if (mode == "gray") { + config_.imdecode_flag = cv::IMREAD_GRAYSCALE; + } else if (mode == "color") { + config_.imdecode_flag = cv::IMREAD_COLOR; + } else { + RCLCPP_ERROR(logger_, "Unknown mode: %s, defaulting to 'unchanged", mode.c_str()); + config_.imdecode_flag = cv::IMREAD_UNCHANGED; + } } + }