5 from geometry_msgs.msg
import PolygonStamped, Point32
6 from jsk_recognition_msgs.msg
import PolygonArray
11 publish_rate = rospy.get_param(
"~publish_rate", 1.0)
13 frame_id = rospy.get_param(
"~frame_id")
14 param = rospy.get_param(
"~polygons")
17 self.
pub_polygons = rospy.Publisher(
"~output", PolygonArray, queue_size=1)
19 self.
timer = rospy.Timer(rospy.Duration(1. / publish_rate), self.
publish)
23 assert isinstance(param, list),
"polygons must be list" 25 has_label = any(
"label" in p
for p
in param)
26 has_likelihood = any(
"likelihood" in p
for p
in param)
29 assert "points" in polygon
and isinstance(polygon[
"points"], list),\
30 "each polygon must have at least 1 'points'" 31 for point
in polygon[
"points"]:
32 assert len(point) == 3,\
33 "element of 'points' must be list of 3 numbers" 35 assert "label" in polygon,
"missing 'label'" 37 assert "likelihood" in polygon,
"missing 'likelihood'" 41 msg.header.frame_id = frame_id
44 ps.header.frame_id = frame_id
45 ps.polygon.points = [Point32(*v)
for v
in polygon[
"points"]]
46 msg.polygons.append(ps)
48 msg.labels.append(polygon[
"label"])
50 msg.likelihood.append(polygon[
"likelihood"])
56 self.msg.header.stamp = event.current_real
57 for p
in self.msg.polygons:
58 p.header.stamp = event.current_real
60 self.pub_polygons.publish(self.
msg)
62 if __name__ ==
'__main__':
63 rospy.init_node(
"polygon_array_publisher")
def parse_params(self, param, frame_id)