how to properly use registerCallback in message_filter? [closed]
This is the class I defined to put everything together (i.e., ros subscribers and callback function). Currently, the code gets stuck and doesn't show any error message. I presume that the callback I defined is never called by ts.registerCallback. I appreciate if anyone can help me figure out this issue.
class ImageFeed(object):
def __init__(self, net):
self._net = net
self._bridge = CvBridge()
self._rgb_sub = message_filters.Subscriber('Image_1', ROS_Image)
self._depth_sub = message_filters.Subscriber('Image_2', ROS_Image)
ts = message_filters.TimeSynchronizer([self._rgb_sub, self._depth_sub], 10)
ts.registerCallback(self._callback)
def _callback(self, rgb_data, depth_data):
try:
self._rgb = self._bridge.imgmsg_to_cv2(rgb_data, "rgb8")
self._depth = self._bridge.imgmsg_to_cv2(depth_data, "16UC1")
img, obj_mask = evalimage(self._net, self._rgb)
cv2.imwrite('/RGB_image.png', img)
cv2.imwrite('/Depth_image.png', self._depth)
print("Subscribed")
except CvBridgeError as e:
print(e)
Resolved: https://answers.ros.org/question/3154...
So your topics are only approximately synchronised, and not exactly?
I wish that I can exactly synchronize, but I don't have an exact idea about how to do it. I just checked that both images are getting published in roughly 30Hz.
Well, exact time synchronisation requires, as the name implies, timestamps to match exactly for all messages you'd like to synchronise.
Publication rate is only tangentially related to that.
For individual cameras (or sensors in general), you'd need a very precisely synchronised clock and way to synchronise their actions for that to happen I believe. It's typically only seen in devices which are actually composed of multiple sensors which are all linked and share the same clock.
I see. I believe that my rgbd camera system (xtion pro live) shares a same clock for both raw rgb and depth images. However, I'm currently subscribing rectified images and the depth image is also reflected to the RGB camera coordinate. I guess that those post processes mess up the synced time stamp.