0
$\begingroup$

Rosanswers logo

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?


Originally posted by nckswt on ROS Answers with karma: 539 on 2014-03-29

Post score: 1


Original comments

Comment by vdonkey on 2014-05-05:
Hi, have you work it out? I have the same question

Comment by nckswt on 2014-05-29:
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!

Comment by 2ROS0 on 2017-03-16:
@nckswt any solution yet?

Comment by nckswt on 2017-03-16:
I ended up finding a workaround to my problem instead, without having to display the DisparityImage. Sorry, no solution found!

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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
}

Originally posted by malvarado with karma: 80 on 2014-11-30

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.