Ask Your Question
0

Using Synchronizer to batch up image messages

asked 2016-04-11 23:10:50 -0500

KenYN gravatar image

Given the code on this page, if I have a message file batched_image.msg that looks like:

sensor_msgs/Image image
sensor_msgs/CameraInfo info

And code that looks like:

void callback(const ImageConstPtr& image, const CameraInfoConstPtr& cam_info)
{
    batched_image batch;
    batch.image = *image;
    batch.info = *cam_info;
}

This works, of course, but it involves a copy of Image, if I understand correctly. How can I avoid this copy, as in my use case I have four 1280x960 images? Ideally I would like:

sensor_msgs/ImageConstPtr image
sensor_msgs/CameraInfoConstPtr info

But that obviously doesn't work.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-04-12 00:41:08 -0500

ahendrix gravatar image

Publishing a message makes a copy and sends it over the network. ROS doesn't let you send pointers between nodes, because those nodes aren't running in the same memory space, and may not even be running on the same machine.

If you don't need to publish this data structure, and just want to pass it around within your own code, you can just declare a class or a struct containing the pointers, like:

struct ImageWithCameraInfo {
    sensor_msgs::ImageConstPtr image;
    sensor_msgs::CameraInfoConstPtr info;
};
edit flag offensive delete link more

Comments

I'm using Nodelets, so I was under the impression that passing images between Nodelets in the same container was copy-free.

KenYN gravatar image KenYN  ( 2016-04-12 01:01:52 -0500 )edit

yes, but the core ROS message format needs to support the more general use case, so pointer types aren't supported.

ahendrix gravatar image ahendrix  ( 2016-04-12 02:05:06 -0500 )edit

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2016-04-11 23:10:50 -0500

Seen: 66 times

Last updated: Apr 12 '16