Skip to content

Commit 0db3008

Browse files
committed
make default label configurable
1 parent ee918d6 commit 0db3008

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

hydra_ros/include/hydra_ros/input/image_receiver.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,11 @@ struct ColormappedLabelSubscriber {
115115
virtual ~ColormappedLabelSubscriber();
116116

117117
Filter& getFilter() const;
118-
void setColormap(const SemanticColorMap* colormap);
118+
void setColormap(const SemanticColorMap* colormap, int32_t default_label);
119119
void fillInput(const sensor_msgs::msg::Image& img, ImageInputPacket& packet) const;
120120

121121
private:
122+
int32_t default_label_;
122123
const SemanticColorMap* colormap_;
123124
std::shared_ptr<FilterSub<sensor_msgs::msg::Image>> impl_;
124125
};
@@ -247,7 +248,10 @@ class ColormappedLabelImageReceiver
247248
: public ImageReceiverImpl<ColormappedLabelSubscriber> {
248249
public:
249250
struct Config : RosDataReceiver::Config {
251+
//! Path to colormap CSV to use to remap colors to labels
250252
std::filesystem::path colormap_path;
253+
//! Label value to use when value is unknown
254+
int32_t default_label = -1;
251255
} const config;
252256

253257
ColormappedLabelImageReceiver(const Config& config, const std::string& sensor_name);

hydra_ros/src/input/image_receiver.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,13 @@ void LabelSubscriber::fillInput(const Image& img, ImageInputPacket& packet) cons
122122
}
123123
}
124124

125-
ColormappedLabelSubscriber::ColormappedLabelSubscriber() : colormap_(nullptr) {}
125+
ColormappedLabelSubscriber::ColormappedLabelSubscriber()
126+
: default_label_(-1), colormap_(nullptr) {}
126127

127128
ColormappedLabelSubscriber::ColormappedLabelSubscriber(ianvs::NodeHandle nh,
128129
uint32_t queue_size)
129-
: colormap_(nullptr),
130+
: default_label_(-1),
131+
colormap_(nullptr),
130132
impl_(std::make_shared<FilterSub<Image>>(nh, "semantic/image_raw", queue_size)) {}
131133

132134
ColormappedLabelSubscriber::~ColormappedLabelSubscriber() = default;
@@ -135,8 +137,10 @@ ColormappedLabelSubscriber::Filter& ColormappedLabelSubscriber::getFilter() cons
135137
return *CHECK_NOTNULL(impl_);
136138
}
137139

138-
void ColormappedLabelSubscriber::setColormap(const SemanticColorMap* colormap) {
140+
void ColormappedLabelSubscriber::setColormap(const SemanticColorMap* colormap,
141+
int32_t default_label) {
139142
colormap_ = colormap;
143+
default_label_ = default_label;
140144
}
141145

142146
void ColormappedLabelSubscriber::fillInput(const Image& img,
@@ -164,9 +168,8 @@ void ColormappedLabelSubscriber::fillInput(const Image& img,
164168
for (int c = 0; c < colors.cols; ++c) {
165169
const auto& pixel = colors.at<cv::Vec3b>(r, c);
166170
const spark_dsg::Color color(pixel[0], pixel[1], pixel[2]);
167-
// this is lazy, but works out to the same invalid label we normally use
168171
packet.labels.at<int32_t>(r, c) =
169-
colormap_->getLabelFromColor(color).value_or(-1);
172+
colormap_->getLabelFromColor(color).value_or(default_label_);
170173
}
171174
}
172175
}
@@ -262,7 +265,7 @@ ColormappedLabelImageReceiver::ColormappedLabelImageReceiver(const Config& confi
262265
bool ColormappedLabelImageReceiver::initImpl() {
263266
using Base = ImageReceiverImpl<ColormappedLabelSubscriber>;
264267
const auto ret = Base::initImpl();
265-
semantic_sub_.setColormap(colormap_.get());
268+
semantic_sub_.setColormap(colormap_.get(), config.default_label);
266269
return ret;
267270
}
268271

@@ -271,6 +274,7 @@ void declare_config(ColormappedLabelImageReceiver::Config& config) {
271274
name("ColormappedLabelImageReceiver::Config");
272275
base<hydra::RosDataReceiver::Config>(config);
273276
field<Path::Absolute>(config.colormap_path, "colormap_path");
277+
field(config.default_label, "default_label");
274278
check<Path::Exists>(config.colormap_path, "colormap_path");
275279
}
276280

0 commit comments

Comments
 (0)