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

how to subscribe disparity image?

asked 2014-11-13 10:36:50 -0500

Robot gravatar image

I have started working with stereo camera. I have the disparity image on the /stereo/disparity topic. Now I want to subcribe that stereo_msgs/DisparityImage form the /stereo/disparity topic. For subscribing this is

image_transport::ImageTransport it(nh);

image_transport::Subscriber sub = it.subscribe("/stereo/disparity", 1, imageCallback);

enough? Or do i have to use some other transport for disparity image. .

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2014-11-13 19:12:45 -0500

I am not sure image_transport can handle stereo_msgs/DisparityImage, probably it can. In such case just make sure that imageCallback has the following signature:

void imageCallback(const stereo_msgs::DisparityImage& msg);

If that doesn't work, this will work for sure:

#include <ros/ros.h>
#include <stereo_msgs/DisparityImage.h>

void disparityImageCallback(const stereo_msgs::DisparityImage& msg)
{
    //Do cool stuff here
}

....

int main (int argc, char **argv)
{
  ...
  ros::NodeHandle nh;
  ros::Subscriber sub = nh.subscribe("/stereo/disparity", 1, disparityImageCallback);

  ...
}
edit flag offensive delete link more

Comments

thank you very much... it worked..

Robot gravatar image Robot  ( 2014-11-14 02:29:17 -0500 )edit

Glad I could help :)

Martin Peris gravatar image Martin Peris  ( 2014-11-14 03:13:28 -0500 )edit

well now i am stuck with the image encodings and step size.. do ypu have any idea about the format of the disparity image.. thanks in advance

Robot gravatar image Robot  ( 2014-11-14 03:30:05 -0500 )edit

Well, inside the DisparityImage structure there is a field called image with all the information you need. The field image contains a string called enconding and a uint32 step so you can figure out how to interpret the raw data

Martin Peris gravatar image Martin Peris  ( 2014-11-16 18:52:33 -0500 )edit

Thanks again.. the step field is visible but if I try to print the encoding it is showing an error..

error: cannot pass objects of non-trivially-copyable type ‘sensor_msgs::Image_<std::allocator<void> >::_encoding_type {aka struct std::basic_string<char>}’ through ‘...’

Robot gravatar image Robot  ( 2014-11-17 02:44:55 -0500 )edit

Remember that encoding is a message of type string and therefore to access the actual string of characters you need to reference it as encoding.data

Martin Peris gravatar image Martin Peris  ( 2014-11-17 18:59:14 -0500 )edit

Hello there, Thanks for this answer. I know its have been a while, but, I am not sure how to handle the msg object in disparityImageCallback. I am trying to get the image as msg->image but is not working...

CesarHoyosM gravatar image CesarHoyosM  ( 2017-06-28 06:59:17 -0500 )edit
1

Since disparityImageCallback receives a reference to a stereo_msgs/DisparityImage, msg.image should be the way to go

Martin Peris gravatar image Martin Peris  ( 2017-07-06 19:54:39 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-11-13 10:36:50 -0500

Seen: 1,130 times

Last updated: Nov 13 '14