def show_points_in_box(points, bboxes, bbox_corners, surfaces, point_masks, is_yx_zb):
      if is_yx_zb:
        bboxes = Bbox3D.convert_from_yx_zb_boxes(bboxes)

      pn_in_box = np.sum(point_masks, 0)

      bn = bboxes.shape[0]
      points_in_boxes = []
      for i in range(bn):
        points_in_boxes.append( points[point_masks[:,i]] )

      pcd0 = points2pcd_open3d(points[:,:3])
      pcd0_aug = points2pcd_open3d(points[:,:3]-np.array([[0,0,4]]))

      corner_pcds = [points2pcd_open3d(corners) for corners in bbox_corners]
      surface_pcds = [points2pcd_open3d(surface) for surface in surfaces]
      points_inb_pcds = [points2pcd_open3d(points[:,:3]) for points in points_in_boxes]
      bboxes_ls0 = [Bbox3D.draw_bbox_open3d(box, 'Z') for box in bboxes]
      frame_mesh = open3d.create_mesh_coordinate_frame(size = 2.0, origin = bboxes[0,0:3])

      points_inb_pcds_valid = [pcd for i,pcd in enumerate(points_inb_pcds) if pn_in_box[i]>0]
      open3d.draw_geometries( bboxes_ls0 + points_inb_pcds_valid + [pcd0_aug])

      show_corners = False
      show_surfaces = False
      show_points_inb = False
      for i in range(bn):
        frame_mesh = open3d.create_mesh_coordinate_frame(size = 2.0, origin = bboxes[i,0:3])
        if show_corners:
          open3d.draw_geometries(bboxes_ls0[i:i+1]+corner_pcds[i:i+1]+[frame_mesh])
        if show_surfaces:
          open3d.draw_geometries(bboxes_ls0[i:i+1]+surface_pcds[i:i+1]+[frame_mesh])
        if show_points_inb:
          open3d.draw_geometries(bboxes_ls0[i:i+1]+points_inb_pcds[i:i+1]+[frame_mesh])
          pass
Ejemplo n.º 2
0
def pth_to_txt(pth_fn):
    '''
    class_2_label0 = {'background':0,'wall':1, 'window':2, 'door':3,
                    'ceiling':5, 'floor': 4, 'room':6}
  '''
    res = torch.load(pth_fn)
    bboxes = [r.bbox3d for r in res]
    labels = [r.get_field('labels') for r in res]
    n = len(bboxes)
    path = os.path.dirname(pth_fn) + '/text_models'
    if not os.path.exists(path):
        os.makedirs(path)
    for i in range(n):
        txt_fn = os.path.join(path, f'room_{i}.txt')
        boxes = Bbox3D.convert_from_yx_zb_boxes(bboxes[i].data.numpy())
        room = np.concatenate([boxes, labels[i].reshape(-1, 1)], 1)
        np.savetxt(txt_fn, room)
        print(f'save {txt_fn} ok')
    pass