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

Synchronizing image display and services between two ROS nodes

asked 2011-06-11 02:26:36 -0600

Pi Robot gravatar image

Now that I have been put on the right track for synchronizing topics, I would like to do something similar between an image message topic and a service that draws a marker (e.g. rectangle) on that image.

So I have a "display node" that subscribes to an image topic and uses cv_bridge and the OpenCV ShowImage function to display the image. Then I define a service within this node, that accepts time stamped ROI messages and displays a rectangle on the image using OpenCV's Rectangle function.

A second node also subscribes to the image topic and looks for faces using the OpenCV Haar detector. When it finds a face, it sends a service request to the display node to draw a rectangle around the ROI that surrounds the face.

The trouble is that the displayed rectangle lags the movement of the face in the image by a noticeable amount--about 0.5 seconds. It doesn't matter if I stamp the ROI service request with the image timestamp or rospy.Time.now(). I now know from the link above how to synchronize two ROS topics to fix this problem, but can I do something similar between a ROS topic and a service?

Thanks!
--patrick

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2011-06-11 03:43:13 -0600

dornhege gravatar image

I can't think of a clean solution, but the odd one would be somewhat the same as for topics. You have a timesynchronizer in the same way as for topics. One of the topics in there is the ROI message from the service request type, that you subscribe for the time synchronizer.

Upon the service call you now publish the request to that internal topic (Using a pointer to avoid serialization), so that it will be time synchronized.

edit flag offensive delete link more

Comments

Yeah, I was thinking along similar lines. But if I go that route, I wonder if I should instead just use a "markers" topic with a message type that defines the type of marker, ROI and header, and have all the detector nodes publish their markers to that same topic. I've never tried having more than one node publish to the same topic. Is that something that is generally a bad idea?
Pi Robot gravatar image Pi Robot  ( 2011-06-11 06:04:42 -0600 )edit
I have tried your recommended strategy and it works. The only thing I don't know how to do is how to avoid serialization when republishing the service request. You said to use a pointer but since I'm using Python, I'm guessing that is not an option? Is there a way in Python to avoid serialization?
Pi Robot gravatar image Pi Robot  ( 2011-06-11 11:12:12 -0600 )edit
Ooops. Looks like a spoke too soon. I just added a second test detector node that tries to draw random markers on the display image using the service approach and while its markers show up on the display, the face boxes from my first detector node (the OpenCV Haar face detector) no longer show up! If I turn off the second test node, I see the face boxes again...
Pi Robot gravatar image Pi Robot  ( 2011-06-11 11:22:24 -0600 )edit
OK, I found a kludgey solution to the above problem. Since I was clearing the marker image after each frame, the face boxes were simply disappearing before I could see them. (I was publishing the random markers from the second test detector much faster.) So now I clear the marker image after N number of frames and I now see both sets of markers. Once nice "feature" of this fix is that as you increase the value of N, you see a longer and longer history of each marker on the screen. Unless someone can come up with a better idea, I'm going to mark this question answered.
Pi Robot gravatar image Pi Robot  ( 2011-06-11 11:56:34 -0600 )edit

Question Tools

Stats

Asked: 2011-06-11 02:26:36 -0600

Seen: 1,079 times

Last updated: Jun 11 '11