Go to the documentation of this file.00001
00002
00003 from jsk_recognition_msgs.msg import BoundingBoxArray
00004 from jsk_topic_tools import ConnectionBasedTransport
00005 import message_filters
00006 import rospy
00007
00008
00009 class AddBoundingBoxArray(ConnectionBasedTransport):
00010 def __init__(self):
00011 super(AddBoundingBoxArray, self).__init__()
00012 self._pub = self.advertise('~output', BoundingBoxArray, queue_size=1)
00013
00014 def subscribe(self):
00015 topics = rospy.get_param('~topics')
00016 self.subs = []
00017 for tp in topics:
00018 sub = message_filters.Subscriber(tp, BoundingBoxArray)
00019 self.subs.append(sub)
00020 use_async = rospy.get_param('~approximate_sync', False)
00021 queue_size = rospy.get_param('~queue_size', 100)
00022 if use_async:
00023 slop = rospy.get_param('~slop', 0.1)
00024 sync = message_filters.ApproximateTimeSynchronizer(
00025 self.subs, queue_size, slop)
00026 else:
00027 sync = message_filters.TimeSynchronizer(self.subs, queue_size)
00028 sync.registerCallback(self._decompose)
00029
00030 def unsubscribe(self):
00031 for sub in self.subs:
00032 sub.unregister()
00033
00034 def _decompose(self, *bboxes_msgs):
00035 out_msg = BoundingBoxArray()
00036 out_msg.header = bboxes_msgs[0].header
00037 for bboxes_msg in bboxes_msgs:
00038 out_msg.boxes.extend(bboxes_msg.boxes)
00039 self._pub.publish(out_msg)
00040
00041
00042 if __name__ == '__main__':
00043 rospy.init_node('add_bounding_box_array')
00044 app = AddBoundingBoxArray()
00045 rospy.spin()