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

Revision history [back]

click to hide/show revision 1
initial version

I think I originally took part of the code from stereo_image_proc. I guess your two webcams are not synchronized, so the following code uses approximate sync. If they are synchronized you can use exact sync in the same way.

These are your includes:

#include <sensor_msgs/Image.h>
#include <image_transport/subscriber_filter.h>
#include <message_filters/sync_policies/approximate_time.h>

And don't forget to add the corresponding dependencies in your manifest.xml/package.xml!

Subscribe to the right topics and register what callback function to call, this could go into your main function:

ros::NodeHandle nh;
image_transport::SubscriberFilter left_sub, right_sub;
image_transport::ImageTransport it(nh);
left_sub.subscribe(it, "left_topic", 1, "raw");
right_sub.subscribe(it, "right_topic", 1, "raw");

typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::Image, sensor_msgs::Image> ApproximatePolicy;
typedef message_filters::Synchronizer<ApproximatePolicy> ApproximateSync;

boost::shared_ptr<ApproximateSync> approximate_sync;

approximate_sync.reset(new ApproximateSync(ApproximatePolicy(queue_size),left_sub,right_sub));
approximate_sync->registerCallback(boost::bind(callback, _1, _2));

ros::spin();

Define your callback function:

void callback(const sensor_msgs::ImageConstPtr& l_image_msg, 
              const sensor_msgs::ImageConstPtr& r_image_msg){
    ROS_INFO("Callback reached! :-)");
}

Probably I forgot some stuff so I will try to update my answer!

Good luck!