how to properly use registerCallback in message_filter? [closed]

asked 2021-10-08 12:31:20 -0600

kidpaul gravatar image

updated 2021-10-08 12:36:20 -0600

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)
edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by gvdhoorn
close date 2021-10-09 03:10:06.380468

Comments

kidpaul gravatar image kidpaul  ( 2021-10-09 01:11:59 -0600 )edit

So your topics are only approximately synchronised, and not exactly?

gvdhoorn gravatar image gvdhoorn  ( 2021-10-09 03:10:25 -0600 )edit

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.

kidpaul gravatar image kidpaul  ( 2021-10-09 11:25:04 -0600 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2021-10-10 04:19:12 -0600 )edit

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.

kidpaul gravatar image kidpaul  ( 2021-10-10 12:20:48 -0600 )edit