evaluate_voxel_segmentation_by_gt_box.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from jsk_recognition_msgs.msg import Accuracy
4 from jsk_recognition_msgs.msg import BoundingBox
5 import jsk_recognition_utils
6 from jsk_topic_tools import ConnectionBasedTransport
7 import rospy
8 from visualization_msgs.msg import MarkerArray
9 
10 
11 class EvaluateVoxelSegmentationByGTBox(ConnectionBasedTransport):
12 
13  def __init__(self):
14  super(EvaluateVoxelSegmentationByGTBox, self).__init__()
15  self.box_gt = None
16  self.marker_ns = rospy.get_param('~marker_ns', None)
17  if self.marker_ns is not None:
18  self.marker_ns = str(self.marker_ns)
19  self.pub = self.advertise('~output', Accuracy, queue_size=1)
20  self.sub_box_gt = rospy.Subscriber(
21  '~input/box_gt', BoundingBox, self._cb_box_gt)
22 
23  def subscribe(self):
24  self.sub_voxels = rospy.Subscriber(
25  '~input/markers', MarkerArray, self._cb_markers)
26 
27  def unsubscribe(self):
28  self.sub_voxels.unregister()
29 
30  def _cb_box_gt(self, box_msg):
32 
33  def _cb_markers(self, markers_msg):
34  if self.box_gt is None:
35  rospy.logwarn('GT. box is not set, skipping.')
36  return
37 
38  v_intersect = 0
39  v_voxels = 0
40  for marker in markers_msg.markers:
41  if self.marker_ns and self.marker_ns != marker.ns:
42  continue
43  dim_x = marker.scale.x
44  dim_y = marker.scale.y
45  dim_z = marker.scale.z
46  v_voxel = dim_x * dim_y * dim_z
47  for point in marker.points:
48  center_x = point.x
49  center_y = point.y
50  center_z = point.z
51  x1 = center_x - dim_x / 2.
52  x2 = center_x + dim_x / 2.
53  y1 = center_y - dim_y / 2.
54  y2 = center_y + dim_y / 2.
55  z1 = center_z - dim_z / 2.
56  z2 = center_z + dim_z / 2.
57  voxel = (x1, y1, z1, x2, y2, z2)
59  self.box_gt, voxel, return_volumes=True)
60  v_intersect += v_tp
61  v_voxels += v_voxel
62 
63  x1, y1, z1, x2, y2, z2 = self.box_gt
64  v_box = (x2 - x1) * (y2 - y1) * (z2 - z1)
65 
66  v_union = v_voxels + v_box - v_intersect
67 
68  iu = 1. * v_intersect / v_union
69  out_msg = Accuracy(header=markers_msg.markers[0].header, accuracy=iu)
70  self.pub.publish(out_msg)
71 
72 
73 if __name__ == '__main__':
74  rospy.init_node('evaluate_voxel_segmentation_by_gt_box')
76  rospy.spin()


jsk_pcl_ros_utils
Author(s): Yohei Kakiuchi
autogenerated on Mon May 3 2021 03:03:15