Ask Your Question
1

callback needs access to multiple topics - how?

asked 2011-11-02 01:13:47 -0500

Daniel Canelhas gravatar image

updated 2016-10-24 09:10:55 -0500

ngrennan gravatar image

I'm trying to do some processing on images published by a kinect but this is a general camera-related question.

I would like to use the image_geometry functions contained in the PinholeCameraModel for converting 3d rays to pixels and 2d pixels to 3d rays, while making use of the calibration parameters published under /camera/rgb/camera_info.

The documentation gives an example like this:

image_geometry::PinholeCameraModel model_;

void imageCb(const sensor_msgs::ImageConstPtr& raw_image,
             const sensor_msgs::CameraInfoConstPtr& cam_info)
{
  // Update the camera model (usually a no-op)
  model_.fromCameraInfo(cam_info);

  // Do processing...
}

Defining a subscriber like this doesn't work though:

ros::Subscriber sub = n.subscribe("/camera/rgb/image_rect /camera/rgb/camera_info", 1, &imageCb);

I'm guessing that I have to do something to group the image with the camera_info into one single message, perhaps with image_transport(?), but I don't have any idea how to do this. I suppose i could create a separate callback for the camera info and update some global variable that the other callback could access but I think that's a less than ideal solution in general (in this case I'm sure it works, since the calibration parameters are constant).

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
5

answered 2011-11-02 02:45:18 -0500

Daniel Canelhas gravatar image

Ok, I think I might have found an answer so:

The problem lies in the use of the ros::Subscriber.

To get both the image and the camera_info simultaneously (and synchronized), use image_transport CameraSubscriber instead.

image_transport::CameraSubscriber sub = it.subscribeCamera("camera/rgb/image", 1, &imageCb);

The callback function can be left as-is.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-11-02 01:13:47 -0500

Seen: 835 times

Last updated: Nov 02 '11