[ros-users] problem using TimeSynchronizer with two images

Top Page
Attachments:
Message as email
+ (text/plain)
+ sync_problem.cpp (text/plain)
Delete this message
Reply to this message
Author: Dan Lazewatsky
Date:  
To: ros-users
Subject: [ros-users] problem using TimeSynchronizer with two images
Hi all -
I'm trying to use TimeSynchronizer to sync up images from two cameras, 
but I'm having some problems. In the following lines:
     message_filters::Subscriber<Image> left_sub(nh, 
"stereo/left/image", 1);
     message_filters::Subscriber<Image> right_sub(nh, 
"stereo/right/image", 1);


     TimeSynchronizer<Image, Image> sync(left_sub, right_sub, 10);
     sync.registerCallback(boost::bind(&callback, _1, _2));
in the callback, both left and right appear to be the same image (they 
both seem to come from the rightmost subscriber given to sync). I've 
checked stereo/left/image and stereo/right/image with image_view and 
they are definitely different. Is there something I'm missing here? Code 
to reproduce is attached.


On a related note, is there a way to use TimeSynchronizer with
image_transport rather than subscribing to the image directly?

Thanks,
-Dan
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/CvBridge.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>

#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include <sensor_msgs/Image.h>

using namespace message_filters;
using namespace sensor_msgs;

sensor_msgs::CvBridge bridge;

void callback(const ImageConstPtr& left, const ImageConstPtr& right) {
    IplImage* im_left    = bridge.imgMsgToCv(left,  "rgb8");
    IplImage* im_right    = bridge.imgMsgToCv(right, "rgb8");

    
    cvShowImage("left", im_left);
    cvShowImage("right", im_right);
}


int main(int argc, char **argv) {
    ros::init(argc, argv, "sync_node");
    ros::NodeHandle nh;

        
    cvNamedWindow("left");
    cvNamedWindow("right");
    cvStartWindowThread();

    
    message_filters::Subscriber<Image> left_sub(nh, "stereo/left/image", 1);
    message_filters::Subscriber<Image> right_sub(nh, "stereo/right/image", 1);

    
    TimeSynchronizer<Image, Image> sync(left_sub, right_sub, 10);
    sync.registerCallback(boost::bind(&callback, _1, _2));

    
    ros::spin();
    return 0;
}