add_bounding_box_array.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from jsk_recognition_msgs.msg import BoundingBoxArray
4 from jsk_topic_tools import ConnectionBasedTransport
5 import message_filters
6 import rospy
7 
8 
9 class AddBoundingBoxArray(ConnectionBasedTransport):
10  def __init__(self):
11  super(AddBoundingBoxArray, self).__init__()
12  self._pub = self.advertise('~output', BoundingBoxArray, queue_size=1)
13 
14  def subscribe(self):
15  topics = rospy.get_param('~topics')
16  self.subs = []
17  for tp in topics:
18  sub = message_filters.Subscriber(tp, BoundingBoxArray)
19  self.subs.append(sub)
20  use_async = rospy.get_param('~approximate_sync', False)
21  queue_size = rospy.get_param('~queue_size', 100)
22  if use_async:
23  slop = rospy.get_param('~slop', 0.1)
24  sync = message_filters.ApproximateTimeSynchronizer(
25  self.subs, queue_size, slop)
26  else:
27  sync = message_filters.TimeSynchronizer(self.subs, queue_size)
28  sync.registerCallback(self._decompose)
29 
30  def unsubscribe(self):
31  for sub in self.subs:
32  sub.unregister()
33 
34  def _decompose(self, *bboxes_msgs):
35  out_msg = BoundingBoxArray()
36  out_msg.header = bboxes_msgs[0].header
37  for bboxes_msg in bboxes_msgs:
38  out_msg.boxes.extend(bboxes_msg.boxes)
39  self._pub.publish(out_msg)
40 
41 
42 if __name__ == '__main__':
43  rospy.init_node('add_bounding_box_array')
45  rospy.spin()


jsk_recognition_utils
Author(s):
autogenerated on Wed May 27 2020 03:59:48