コード例 #1
0
def add_difficulty_to_annos_v2(info):
    v_path = info['velodyne_path']
    num_features = info['pointcloud_num_features']
    points = np.fromfile(os.path.join(data_root, v_path),
                         dtype=np.float32,
                         count=-1).reshape([-1, num_features])

    annos = info['annos']
    dims = annos['dimensions']  # lwh format
    loc = annos['location']  # xyz in camera
    rots = annos['rotation_y']  # rad in camera

    rect = info['calib/R0_rect']
    Trv2c = info['calib/Tr_velo_to_cam']

    gt_boxes_lidar = np.concatenate([loc, dims, rots[..., np.newaxis]], axis=1)

    gt_boxes = copy.deepcopy(gt_boxes_lidar)
    gt_point_table = box_np_ops.points_in_rbbox(points, gt_boxes)
    gt_point_count = gt_point_table.sum(axis=0)
    annos["num_points"] = gt_point_count

    gt_boxes = copy.deepcopy(gt_boxes_lidar)
    gt_boxes[:, 3:6] = gt_boxes[:, 3:6] + np.array([1.2, 0.5, 8])
    gt_point_table = box_np_ops.points_in_rbbox(points, gt_boxes)
    gt_point_count = gt_point_table.sum(axis=0)
    annos["difficulty"] = gt_point_count
コード例 #2
0
    def save_pointcloud(self, idx):
        point_color = self.w_config.get("PointColor")[:3]
        point_color = (*point_color, self.w_config.get("PointAlpha"))
        point_color = np.tile(np.array(point_color), [self.points.shape[0], 1])
        point_size = np.full([self.points.shape[0]], self.w_config.get("PointSize"), dtype=np.float32)
        if 'annos' in self.info:
            gt_point_table = box_np_ops.points_in_rbbox(self.points, self.gt_boxes)
            self.gt_filled_mask = gt_point_table.sum(axis=0)
            gt_point_mask = gt_point_table.any(1)
            point_size[gt_point_mask] = self.w_config.get("GTPointSize")
            gt_point_color = self.w_config.get("GTPointColor")
            gt_point_color = (*gt_point_color[:3], self.w_config.get("GTPointAlpha"))
            point_color[gt_point_mask] = gt_point_color

        range = np.array([self.w_config.get("CoorsRange")])
        # range = np.zeros(range.shape, dtype=range.dtype)
        # range[0] = [-30, -38.4, -10.5, 51.92, 38.4, 9.5]
        bbox = box_np_ops.minmax_to_corner_3d(range)
        self.w_pc_viewer.boxes3d("bound", bbox, GLColor.Green)

        self.w_pc_viewer.remove("dt_boxes/labels")
        self.w_pc_viewer.remove("dt_boxes")
        if self.detection_annos is not None and self.w_config.get("DrawDTBoxes"):
            detection_anno = self.detection_annos[idx]
            self.draw_detection(detection_anno)
        self.w_pc_viewer.scatter(
            "pointcloud", self.points[:, :3], point_color, size=point_size)
コード例 #3
0
def noise_per_object(gt_boxes,
                     points=None,
                     valid_mask=None,
                     rotation_perturb=(5.0 / 180) * np.pi,
                     center_noise_std=0.15,
                     global_random_rot_range=(2.0 / 180) * np.pi,
                     num_try=100):

    num_boxes = gt_boxes.shape[0]
    rotation_perturb = [-rotation_perturb, rotation_perturb]
    center_noise_std = [center_noise_std, center_noise_std, center_noise_std]
    if valid_mask is None:
        valid_mask = np.ones((num_boxes, ), dtype=np.bool_)

    center_noise_std = np.array(center_noise_std, dtype=gt_boxes.dtype)
    loc_noises = np.random.normal(scale=center_noise_std,
                                  size=[num_boxes, num_try, 3])
    rot_noises = np.random.uniform(rotation_perturb[0],
                                   rotation_perturb[1],
                                   size=[num_boxes, num_try])
    global_rot_noises = np.random.uniform(-global_random_rot_range,
                                          global_random_rot_range,
                                          size=[num_boxes, num_try])
    point_masks = box_np_ops.points_in_rbbox(points, gt_boxes)
    enable_grot = False
    if global_random_rot_range > (0.01 / 180) * np.pi:
        enable_grot = True
    if not enable_grot:
        selected_noise = noise_per_box(gt_boxes[:, [0, 1, 3, 4, 6]],
                                       valid_mask, loc_noises, rot_noises)
    else:
        selected_noise = noise_per_box_v2_(gt_boxes[:, [0, 1, 3, 4, 6]],
                                           valid_mask, loc_noises, rot_noises,
                                           global_rot_noises)

    loc_transforms = _select_transform(loc_noises, selected_noise)
    rot_transforms = _select_transform(rot_noises, selected_noise)

    points_transform_(points, gt_boxes[:, :3], point_masks, loc_transforms,
                      rot_transforms, valid_mask)
    box3d_transform_(gt_boxes, loc_transforms, rot_transforms, valid_mask)
コード例 #4
0
    def plot_pointcloud(self):
        point_color = self.w_config.get("PointColor")[:3]
        point_color = (*point_color, self.w_config.get("PointAlpha"))
        point_color = np.tile(np.array(point_color), [self.points.shape[0], 1])

        point_size = np.full(
            [self.points.shape[0]],
            self.w_config.get("PointSize"),
            dtype=np.float32)

        self.w_pc_viewer.draw_bounding_box(self.w_config.get("CoorsRange"))
        if self.gt_boxes is not None and len(self.gt_boxes) > 0:
            gt_boxes = copy.deepcopy(self.gt_boxes)
            # gt_boxes[:, 3:6] = gt_boxes[:, 3:6] + np.array([1.2, 0.8, 8])
            # gt_boxes[:, 2] = gt_boxes[:, 2] + np.array([1])
            gt_point_table = box_np_ops.points_in_rbbox(self.points, gt_boxes)
            self.gt_filled_mask = gt_point_table.sum(axis=0)
            gt_point_mask = gt_point_table.any(1)
            point_size[gt_point_mask] = self.w_config.get("GTPointSize")
            gt_point_color = self.w_config.get("GTPointColor")
            gt_point_color = (*gt_point_color[:3], self.w_config.get("GTPointAlpha"))
            point_color[gt_point_mask] = gt_point_color

        self.w_pc_viewer.remove("gt_boxes/labels")
        self.w_pc_viewer.remove("gt_boxes")
        if self.gt_names is not None and len(self.gt_names) > 0 and self.w_config.get("DrawGTBoxes"):
            self.plot_gt_boxes_in_pointcloud()

        self.w_pc_viewer.remove("dt_boxes/labels")
        self.w_pc_viewer.remove("dt_boxes")
        if self.detection_annos is not None and len(self.detection_annos) > 0 and self.w_config.get("DrawDTBoxes"):
            detection_anno = self.detection_annos[self.current_idx]
            self.draw_detection(detection_anno)

        self.w_pc_viewer.remove("anchors")
        if self.plot_anchors:
            self.plot_anchors_in_pointcloud()

        self.w_pc_viewer.scatter(
            "pointcloud", self.points[:, :3], point_color, size=point_size)
コード例 #5
0
def remove_points_outside_boxes(points, boxes):
    masks = box_np_ops.points_in_rbbox(points, boxes)
    points = points[masks.any(-1)]
    return points
コード例 #6
0
def remove_points_in_boxes(points, boxes):
    masks = box_np_ops.points_in_rbbox(points, boxes)
    points = points[np.logical_not(masks.any(-1))]
    return points