ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Disparity image publishing [closed]

asked 2011-03-20 23:43:30 -0500

prbhagwat gravatar image

updated 2011-03-21 05:47:56 -0500

tfoote gravatar image

Hi, I am new to opencv. Need some help in publishing the disparity image in ROS. i am getting left, right and disparity images from the custom stereo camera SDK. The disparity image that i am getting from SDK is mono8 format. Now i want to publish the disparity image from the ROS so that "disparity_view" can display the disparity image. It looks the disparity_view expects the images to be in TYPE_32FC1 format, but the disparity image that i have is mono8 format because of this it is not able to display disparity image.

Is there any sample program or tutorial which will guide to publish disparity image in TYPE_32FC1 format from mono8 format.

Warm Regards, pramod

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Miquel Massot
close date 2015-06-25 02:45:35.375870

Comments

i'm going to add some lines of code, the question has an answer but with code is better ;-)

Augusto Luis Ballardini gravatar image Augusto Luis Ballardini  ( 2015-06-30 05:59:45 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
2

answered 2011-04-01 11:52:44 -0500

Patrick Mihelich gravatar image

disparity_view expects disparities to have type float, so you'll need to convert your uint8_t disparity values. In your DisparityImage message, resize image.data to width * size * sizeof(float), and get a float pointer to your data buffer: float* ptr = reinterpret_cast<float*>(&image.data[0]). Then copy the disparities over one by one. You may need to scale the uint8_t disparities down by some factor if the custom SDK does sub-pixel correspondence like OpenCV's block matcher. The float disparities are in pixels. Don't forget to set image.encoding = sensor_msgs::image_encodings::TYPE_32FC1.

edit flag offensive delete link more
2

answered 2015-06-24 12:47:22 -0500

updated 2015-06-30 06:07:48 -0500

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);
edit flag offensive delete link more
0

answered 2011-03-21 05:49:04 -0500

tfoote gravatar image

I suggest you look at stereo_image_proc which is the default way to both compute and send disparity images.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2011-03-20 23:43:30 -0500

Seen: 3,851 times

Last updated: Jun 30 '15