def iou2d(box_a, box_b): boxa_corners = np.array(BBox.box2corners2d(box_a))[:, :2] boxb_corners = np.array(BBox.box2corners2d(box_b))[:, :2] reca, recb = Polygon(boxa_corners), Polygon(boxb_corners) overlap = reca.intersection(recb).area area_a = reca.area area_b = recb.area iou = overlap / (area_a + area_b - overlap + 1e-10) return iou
def handler_box(self, box: BBox, message: str = '', color='red'): corners = np.array(BBox.box2corners2d(box))[:, :2] corners = np.concatenate([corners, corners[0:1, :2]]) plt.plot(corners[:, 0], corners[:, 1], color=self.COLOR_MAP[color]) plt.text(corners[0, 0] - 1, corners[0, 1] - 1, message, color=self.COLOR_MAP['black'])
def iou3d(box_a, box_b): boxa_corners = np.array(BBox.box2corners2d(box_a)) boxb_corners = np.array(BBox.box2corners2d(box_b))[:, :2] reca, recb = Polygon(boxa_corners), Polygon(boxb_corners) overlap_area = reca.intersection(recb).area iou_2d = overlap_area / (reca.area + recb.area - overlap_area) ha, hb = box_a.h, box_b.h za, zb = box_a.z, box_b.z overlap_height = max( 0, min((za + ha / 2) - (zb - hb / 2), (zb + hb / 2) - (za - ha / 2))) overlap_volume = overlap_area * overlap_height union_volume = box_a.w * box_a.l * ha + box_b.w * box_b.l * hb - overlap_volume iou_3d = overlap_volume / union_volume union_height = max(za + ha / 2, zb + hb / 2) - min(za - ha / 2, zb - hb / 2) return iou_2d, iou_3d
def viewable_corner(bbox: BBox, ego): # nearest corner, viewable corner ego_location = ego[:2] corners = np.array(BBox.box2corners2d(bbox))[:, :2] dist = corners - ego_location dist = np.sum(dist * dist, axis=1) corner_index = np.argmin(dist) corner_coordiante = corners[corner_index] return corner_index, corner_coordiante