Skip to content

Commit ad7b42c

Browse files
committed
Add support for u16; colormaps
1 parent c90d142 commit ad7b42c

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

include/web_video_server/image_streamer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class ImageTransportImageStreamer : public ImageStreamer
7474
bool initialized_;
7575

7676
void imageCallback(const sensor_msgs::ImageConstPtr &msg);
77+
78+
79+
float min_v_ = NAN, max_v_ = NAN;
80+
int colormap_ = -1;
7781
};
7882

7983
class ImageStreamerType

src/image_streamer.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ ImageTransportImageStreamer::ImageTransportImageStreamer(const async_web_server_
2424
output_height_ = request.get_query_param_value_or_default<int>("height", -1);
2525
invert_ = request.has_query_param("invert");
2626
default_transport_ = request.get_query_param_value_or_default("default_transport", "raw");
27+
28+
min_v_ = request.get_query_param_value_or_default<float>("min", min_v_);
29+
max_v_ = request.get_query_param_value_or_default<float>("max", max_v_);
30+
colormap_ = request.get_query_param_value_or_default<int>("colormap", colormap_);
31+
32+
if(std::isnan(min_v_) && !std::isnan(max_v_)) {
33+
min_v_ = 0;
34+
}
2735
}
2836

2937
ImageTransportImageStreamer::~ImageTransportImageStreamer()
@@ -89,19 +97,23 @@ void ImageTransportImageStreamer::imageCallback(const sensor_msgs::ImageConstPtr
8997
cv::Mat img;
9098
try
9199
{
92-
if (msg->encoding.find("F") != std::string::npos)
93-
{
94-
// scale floating point images
95-
cv::Mat float_image_bridge = cv_bridge::toCvCopy(msg, msg->encoding)->image;
96-
cv::Mat_<float> float_image = float_image_bridge;
97-
double max_val;
98-
cv::minMaxIdx(float_image, 0, &max_val);
99-
100-
if (max_val > 0)
101-
{
102-
float_image *= (255 / max_val);
100+
if (msg->encoding.find("16") != std::string::npos || msg->encoding.find("F") != std::string::npos) {
101+
cv::Mat image_bridge = cv_bridge::toCvCopy(msg, msg->encoding)->image;
102+
103+
double max_val, min_val;
104+
if(std::isnan(min_v_) || std::isnan(min_v_)) {
105+
cv::minMaxIdx(image_bridge, &min_val, &max_val);
106+
} else {
107+
min_val = min_v_;
108+
max_val = max_v_;
109+
}
110+
111+
float scale = 255. / (max_val - min_val);
112+
image_bridge.convertTo(img, CV_8U, scale, -min_val * scale);
113+
114+
if(colormap_ >= 0) {
115+
cv::applyColorMap(img, img, colormap_);
103116
}
104-
img = float_image;
105117
}
106118
else
107119
{

0 commit comments

Comments
 (0)