From 27d3125ecb3c6ad96585a912873762ad7382ffc8 Mon Sep 17 00:00:00 2001 From: Nathan Hughes Date: Thu, 2 Jul 2026 21:58:37 +0000 Subject: [PATCH 1/2] draft instance receiver --- .../include/hydra_ros/input/image_receiver.h | 25 +++++++++ hydra_ros/src/input/image_receiver.cpp | 51 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/hydra_ros/include/hydra_ros/input/image_receiver.h b/hydra_ros/include/hydra_ros/input/image_receiver.h index f60f5a36..388d6166 100644 --- a/hydra_ros/include/hydra_ros/input/image_receiver.h +++ b/hydra_ros/include/hydra_ros/input/image_receiver.h @@ -105,6 +105,22 @@ struct LabelSubscriber { std::shared_ptr> impl_; }; +struct InstanceSubscriber { + public: + using MsgType = sensor_msgs::msg::Image; + using Filter = message_filters::SimpleFilter; + + InstanceSubscriber(); + explicit InstanceSubscriber(ianvs::NodeHandle nh, uint32_t queue_size = 1); + virtual ~InstanceSubscriber(); + + Filter& getFilter() const; + void fillInput(const sensor_msgs::msg::Image& img, ImageInputPacket& packet) const; + + private: + std::shared_ptr> impl_; +}; + struct ColormappedLabelSubscriber { public: using MsgType = sensor_msgs::msg::Image; @@ -235,6 +251,15 @@ class ClosedSetImageReceiver : public ImageReceiverImpl { void declare_config(ClosedSetImageReceiver::Config& config); +class InstanceImageReceiver : public ImageReceiverImpl { + public: + struct Config : RosDataReceiver::Config {}; + InstanceImageReceiver(const Config& config, const std::string& sensor_name); + virtual ~InstanceImageReceiver() = default; +}; + +void declare_config(InstanceImageReceiver::Config& config); + class OpenSetImageReceiver : public ImageReceiverImpl { public: struct Config : RosDataReceiver::Config {}; diff --git a/hydra_ros/src/input/image_receiver.cpp b/hydra_ros/src/input/image_receiver.cpp index 61044360..3a351717 100644 --- a/hydra_ros/src/input/image_receiver.cpp +++ b/hydra_ros/src/input/image_receiver.cpp @@ -122,6 +122,41 @@ void LabelSubscriber::fillInput(const Image& img, ImageInputPacket& packet) cons } } +InstanceSubscriber::InstanceSubscriber() = default; + +InstanceSubscriber::InstanceSubscriber(ianvs::NodeHandle nh, uint32_t queue_size) + : impl_(std::make_shared>(nh, "semantic/image_raw", queue_size)) {} + +InstanceSubscriber::~InstanceSubscriber() = default; + +InstanceSubscriber::Filter& InstanceSubscriber::getFilter() const { + return *CHECK_NOTNULL(impl_); +} + +void InstanceSubscriber::fillInput(const Image& img, ImageInputPacket& packet) const { + cv::Mat mat; + try { + mat = cv_bridge::toCvCopy(img)->image; + } catch (const cv_bridge::Exception& e) { + LOG(ERROR) << "Failed to convert label image: " << e.what(); + } + + if (mat.type() != CV_32SC1) { + LOG(ERROR) << "Invalid encoding for instance+label image"; + return; + } + + packet.labels = cv::Mat(mat.size(), CV_32SC1); + packet.instances = cv::Mat(mat.size(), CV_16SC1); + for (int r = 0; r < mat.rows; ++r) { + for (int c = 0; c < mat.cols; ++c) { + const auto original = mat.at(r, c); + packet.labels.at(r, c) = original >> 16; + packet.instances.at(r, c) = original & 0xFFFF; + } + } +} + ColormappedLabelSubscriber::ColormappedLabelSubscriber() : default_label_(-1), colormap_(nullptr) {} @@ -244,6 +279,16 @@ void declare_config(ClosedSetImageReceiver::Config& config) { base(config); } +InstanceImageReceiver::InstanceImageReceiver(const Config& config, + const std::string& sensor_name) + : ImageReceiverImpl(config, sensor_name) {} + +void declare_config(InstanceImageReceiver::Config& config) { + using namespace config; + name("InstanceImageReceiver::Config"); + base(config); +} + OpenSetImageReceiver::OpenSetImageReceiver(const Config& config, const std::string& sensor_name) : ImageReceiverImpl(config, sensor_name) {} @@ -292,6 +337,12 @@ static const auto closed_registration = ClosedSetImageReceiver::Config, std::string>("ClosedSetImageReceiver"); +static const auto instance_registration = + config::RegistrationWithConfig("InstanceImageReceiver"); + static const auto open_registration = config::RegistrationWithConfig Date: Thu, 2 Jul 2026 23:06:48 +0000 Subject: [PATCH 2/2] namespace labelspace --- hydra_ros/launch/hydra.launch.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hydra_ros/launch/hydra.launch.yaml b/hydra_ros/launch/hydra.launch.yaml index 09abc830..3e7d51f6 100644 --- a/hydra_ros/launch/hydra.launch.yaml +++ b/hydra_ros/launch/hydra.launch.yaml @@ -39,7 +39,7 @@ launch: args: > --config-utilities-file $(var input_config_path) --config-utilities-file $(var hydra_config_path) - --config-utilities-file $(var labelspace_path) + --config-utilities-file $(var labelspace_path)@labelspace --config-utilities-file $(find-pkg-share hydra_ros)/config/sinks/mesh_segmenter_sinks.yaml@frontend/objects --config-utilities-file $(find-pkg-share hydra_ros)/config/sinks/gvd_places_sinks.yaml@frontend/freespace_places --config-utilities-file $(find-pkg-share hydra_ros)/config/sinks/active_window_sinks.yaml@active_window