@@ -24,6 +24,14 @@ ImageTransportImageStreamer::ImageTransportImageStreamer(const async_web_server_
24
24
output_height_ = request.get_query_param_value_or_default <int >(" height" , -1 );
25
25
invert_ = request.has_query_param (" invert" );
26
26
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
+ }
27
35
}
28
36
29
37
ImageTransportImageStreamer::~ImageTransportImageStreamer ()
@@ -89,19 +97,23 @@ void ImageTransportImageStreamer::imageCallback(const sensor_msgs::ImageConstPtr
89
97
cv::Mat img;
90
98
try
91
99
{
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_);
103
116
}
104
- img = float_image;
105
117
}
106
118
else
107
119
{
0 commit comments