Ask Your Question

How to synchronize image and marker display between two ROS nodes

asked 2011-06-10 02:51:00 -0600

Pi Robot gravatar image

updated 2011-06-10 13:21:47 -0600

I have two ROS nodes, a "display node" and a "detector node", that both use cv_bridge and subscribe to the same image topic. The detector node publishes an array of ROI boxes around the objects it is designed to detect (e.g. faces). While I could draw these boxes on an OpenCV image window using the same node, I would like the boxes display along with potentially other markers from other detector nodes.

So I have a display node that listens on both the raw image topic and the detector topics and draws the appropriate boxes on a marker image that it then merges with the raw image topic and updates an OpenCV image display window.

The problem I am having is that the markers (e.g. boxes) significantly lag behind the raw image. For instance, if my detector node uses the Haar face detector, and I move my head, the face boxes trail my head movement by a very noticeable amount. (Maybe half of a second?)

I am guessing this is because the display node can update the raw image display much faster than the detector node can update the face detections. But I'm not sure what I can do about it or if this approach is even a good idea.

UPDATE: Well, I've run into a snag. I have no trouble with the CameraInfo Python example found here. However, I cannot get synchronization to work when trying to synchronize /camera/rgb/image_color (I'm using a Kinect and the openni_camera node) and a test publisher I wrote.

Here are the two test scripts I am using. The first script simply publishes a DetectionArray message about 30 times per second with nothing but the header.stamp field set to The second script subscribes to this topic as well as /camera/rgb/image_color. While the second script successfully prints out the value of header.stamp using the regular rospy.Subscriber callback, I never see the message "Synchronized" from the TimeSynchronizer callback. Looking at the timestamps manually using rostopic echo on the /camera/rgb/image_color and /detections topics shows that they are very close to being synchronized already so I thought this should work.

I must be missing something simple I can't see so any tips would be appreciated!

Here is the publisher script:

#!/usr/bin/env python

""" - Version 0.1 2011-06-10  

import roslib
import rospy
import sys
from std_msgs.msg import String
from pi_rein.msg import *
from pi_rein.srv import *
import message_filters

class TestSync:
    def __init__(self):

        self.test_pub = rospy.Publisher("detections", DetectionArray)

        while not rospy.is_shutdown():
            msg = DetectionArray()
            msg.header.stamp =

def main(args):   
    except KeyboardInterrupt:
        print "Shutting down test pub node."

if __name__ == '__main__':

Here is the script:

#!/usr/bin/env python

""" - Version 0.1 2011-06-10  

import roslib
import ...
edit retag flag offensive close merge delete


Hi Patrick, do you know about this: ? It seems to be a good framework for what you're doing.
Ugo gravatar image Ugo  ( 2011-06-10 03:24:53 -0600 )edit
Thanks Ugo--in fact I am trying to do something similar to REIN using Python. (See my posting on ros-users at And even in the exiting C++/Nodelet REIN framework, I don't see a way to display markers from multiple detector nodes on the same image. If I am just missing it, hopefully someone will point it out as it might help me solve my synchronization issue.
Pi Robot gravatar image Pi Robot  ( 2011-06-10 03:54:53 -0600 )edit
My bad, sorry (in fact I discovered the REIN framework thanks to your post on the mailing list :) ).
Ugo gravatar image Ugo  ( 2011-06-10 03:59:43 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2011-06-10 03:52:13 -0600

dornhege gravatar image

updated 2011-06-10 13:59:12 -0600

You should obey the timestamps. Your detector node sends out the appropriate boxes with the image timestamp.

The display node only displays image+markers from the same timestamp. A Time Synchronizer filter should be applicable for this.

Update: To make it work, try to set the timestamps exactly the same. I.e. for your application: The detector subscribes the image and sends out its detections with the image timestamp (not ros::Time::now()). The display subscribes image and detections for synchronization.

edit flag offensive delete link more


Thanks dornhege--this looks like exactly what I need!
Pi Robot gravatar image Pi Robot  ( 2011-06-10 04:00:19 -0600 )edit
That was it! With the timestamp set to the image timestamp and the synchronizer queue set to 100, it works like a charm. Thanks again!
Pi Robot gravatar image Pi Robot  ( 2011-06-10 14:07:47 -0600 )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


Asked: 2011-06-10 02:51:00 -0600

Seen: 2,841 times

Last updated: Jun 10 '11