37 #include <stereo_msgs/DisparityImage.h>
38 #include <opencv2/highgui/highgui.hpp>
56 void imageCb(
const stereo_msgs::DisparityImageConstPtr& msg);
72 const std::vector<std::string>& argv =
getMyArgv();
75 bool shutdown_on_close = std::find(argv.begin(), argv.end(),
76 "--shutdown-on-close") != argv.end();
79 std::string topic = nh.resolveName(
"image");
83 local_nh.param(
"autosize", autosize,
false);
86 #if CV_MAJOR_VERSION ==2
97 if (msg->min_disparity == 0.0 && msg->max_disparity == 0.0)
100 "max_disparity are not set");
106 "(encoding '32FC1'), but has encoding '%s'",
107 msg->image.encoding.c_str());
112 cv::namedWindow(
window_name_,
false ? cv::WND_PROP_AUTOSIZE : 0);
116 float min_disparity = msg->min_disparity;
117 float max_disparity = msg->max_disparity;
118 float multiplier = 255.0f / (max_disparity - min_disparity);
120 const cv::Mat_<float> dmat(msg->image.height, msg->image.width,
121 (
float*)&msg->image.data[0], msg->image.step);
125 const float*
d = dmat[row];
128 for (; disparity_color < disparity_color_end; ++disparity_color, ++
d) {
129 int index = (*
d - min_disparity) * multiplier + 0.5;
130 index = std::min(255, std::max(0, index));
132 (*disparity_color)[2] =
colormap[3*index + 0];
133 (*disparity_color)[1] =
colormap[3*index + 1];
134 (*disparity_color)[0] =
colormap[3*index + 2];
140 sensor_msgs::RegionOfInterest valid = msg->valid_window;
141 cv::Point tl(valid.x_offset, valid.y_offset), br(valid.x_offset + valid.width, valid.y_offset + valid.height);