37 #include <stereo_msgs/DisparityImage.h> 38 #include <opencv2/highgui/highgui.hpp> 47 static void destroyNode(GtkWidget *widget, gpointer data)
52 static void destroyNodelet(GtkWidget *widget, gpointer data)
75 void imageCb(
const stereo_msgs::DisparityImageConstPtr& msg);
91 const std::vector<std::string>& argv =
getMyArgv();
94 bool shutdown_on_close = std::find(argv.begin(), argv.end(),
95 "--shutdown-on-close") != argv.end();
102 local_nh.
param(
"autosize", autosize,
false);
105 #if CV_MAJOR_VERSION ==2 108 GtkWidget *widget = GTK_WIDGET( cvGetWindowHandle(
window_name_.c_str()) );
109 if (shutdown_on_close)
110 g_signal_connect(widget,
"destroy", G_CALLBACK(destroyNode), NULL);
112 g_signal_connect(widget,
"destroy", G_CALLBACK(destroyNodelet), &
sub_);
124 if (msg->min_disparity == 0.0 && msg->max_disparity == 0.0)
127 "max_disparity are not set");
133 "(encoding '32FC1'), but has encoding '%s'",
134 msg->image.encoding.c_str());
139 cv::namedWindow(
window_name_,
false ? cv::WND_PROP_AUTOSIZE : 0);
143 float min_disparity = msg->min_disparity;
144 float max_disparity = msg->max_disparity;
145 float multiplier = 255.0f / (max_disparity - min_disparity);
147 const cv::Mat_<float> dmat(msg->image.height, msg->image.width,
148 (
float*)&msg->image.data[0], msg->image.step);
152 const float*
d = dmat[row];
155 for (; disparity_color < disparity_color_end; ++disparity_color, ++d) {
156 int index = (*d - min_disparity) * multiplier + 0.5;
157 index = std::min(255, std::max(0, index));
159 (*disparity_color)[2] =
colormap[3*index + 0];
160 (*disparity_color)[1] =
colormap[3*index + 1];
161 (*disparity_color)[0] =
colormap[3*index + 2];
167 sensor_msgs::RegionOfInterest valid = msg->valid_window;
168 cv::Point tl(valid.x_offset, valid.y_offset), br(valid.x_offset + valid.width, valid.y_offset + valid.height);
void imageCb(const stereo_msgs::DisparityImageConstPtr &msg)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::NodeHandle & getNodeHandle() const
#define NODELET_ERROR_THROTTLE(rate,...)
ros::NodeHandle & getPrivateNodeHandle() const
cv::Mat_< cv::Vec3b > disparity_color_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
static unsigned char colormap[]
const std::string TYPE_32FC1
std::string resolveName(const std::string &name, bool remap=true) const
const V_string & getMyArgv() const
ROSCONSOLE_DECL void shutdown()
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)