I'm resuming this very old question
since I'm trying to publish a
disparityImage message, loading the
values from a png file, but I'm stuck
with this. Does anybody have a working
example? Thank you. Augusto
ok I have some code to share
ros::Publisher publisher = node.advertise<stereo_msgs::DisparityImage>("test",1,true);
// Allocate new disparity image message
stereo_msgs::DisparityImagePtr disp_msg = boost::make_shared<stereo_msgs::DisparityImage>();
cv::Mat cv_image;
full_filename_image = dir_image + boost::str(boost::format("%010d") % entries_played ) + ".png";
cv_image = cv::imread(full_filename_image, CV_LOAD_IMAGE_GRAYSCALE);
// you need to know only this params for a basic usage (0-64, st.img.proc default param here)
disp_msg->min_disparity = 0;
disp_msg->min_disparity = 63;
// should be safe
disp_msg->valid_window.x_offset = 0;
disp_msg->valid_window.y_offset = 0;
disp_msg->valid_window.width = 0;
disp_msg->valid_window.height = 0;
disp_msg->T = 0;
disp_msg->f = 0;
disp_msg->delta_d = 0;
disp_msg->header.stamp = ros::Time::now();
disp_msg->header.frame_id = ros::this_node::getName();
disp_msg->header.seq = progress.count(); //a counter, int type
sensor_msgs::Image& dimage = disp_msg->image;
dimage.width = cv_image.size().width ;
dimage.height = cv_image.size().height ;
dimage.encoding = sensor_msgs::image_encodings::TYPE_32FC1;
dimage.step = dimage.width * sizeof(float);
dimage.data.resize(dimage.step * dimage.height);
cv::Mat_<float> dmat(dimage.height, dimage.width, reinterpret_cast<float*>(&dimage.data[0]), dimage.step);
cv_image.convertTo(dmat,dmat.type());
publisher.publish(disp_msg);
i'm going to add some lines of code, the question has an answer but with code is better ;-)