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

Converting stereo_msgs/DisparityImage to sensor_msgs/Image

asked 2014-03-29 18:38:09 -0600

nckswt gravatar image

updated 2016-10-24 09:01:21 -0600

ngrennan gravatar image

I'm looking for a simple way to display a stereo_msgs/DisparityImage topic using mjpeg_server, which needs images in the sensor_msgs/Image format. I'm getting the disparity image from a Kinect thorough the openNI package.

Is there a simple way to convert the disparity image to a flat image, or will I have to write up a custom process to handle the conversion?

edit retag flag offensive close merge delete

Comments

1

Hi, have you work it out? I have the same question

vdonkey gravatar image vdonkey  ( 2014-05-05 20:48:29 -0600 )edit

Not yet! I've been distracted by other things to work on, but I'll get back to that soon and post once I have a solution!

nckswt gravatar image nckswt  ( 2014-05-29 06:00:00 -0600 )edit

@nckswt any solution yet?

2ROS0 gravatar image 2ROS0  ( 2017-03-16 12:18:59 -0600 )edit

I ended up finding a workaround to my problem instead, without having to display the DisparityImage. Sorry, no solution found!

nckswt gravatar image nckswt  ( 2017-03-16 17:03:11 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-11-30 01:02:17 -0600

malvarado gravatar image

updated 2014-11-30 10:13:20 -0600

The stereo_msgs/Disparity Image topic contains a sensor_msgs/Image which you can easily pull out and convert to a 8 bit sensor_msgs/Image using some simple OpenCV operations.

You could imagine something like this:

void disparityCallback(const stereo_msgs::DisparityImagePtr disparity)
{

    cv::Mat_<float> disparityMat(disparity->image.height,
                                               disparity->image.width,
                                               reinterpret_cast<float*>(&(disparity->image.data[0])));

    cv::Mat_<uint8_t> eightBitDisparityMat = disparityMat * (255/disparity->max_disparity);

    sensor_msgs::Image eightBitDisparity;

    uint32_t imageSize = disparity->image.height * disparity->image.width;

    eightBitDisparity.data.resize(imageSize);
    memcpy(&eightBitDisparity.data[0], &(eightBitDisparityMat.at<uint8_t>(0,0)), imageSize);

    // Populate the rest of the sensor_msgs::Image fields
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-03-29 18:38:09 -0600

Seen: 1,283 times

Last updated: Nov 30 '14