Exemple #1
0
    def __call__(self, res, info):

        if res["type"] in ["NuScenesDataset", "LyftDataset"] and "gt_boxes" in info:

            res["lidar"]["annotations"] = {
                "boxes": info["gt_boxes"].astype(np.float32),
                "names": info["gt_names"],
                "tokens": info["gt_boxes_token"],
                "velocities": info["gt_boxes_velocity"].astype(np.float32),
            }

        elif res["type"] == "KittiDataset":

            calib = info["calib"]
            calib_dict = {
                "rect": calib["R0_rect"],
                "Trv2c": calib["Tr_velo_to_cam"],
                "P2": calib["P2"],
            }
            res["calib"] = calib_dict
            if "annos" in info:
                annos = info["annos"]
                # we need other objects to avoid collision when sample
                annos = kitti.remove_dontcare(annos)
                locs = annos["location"]
                dims = annos["dimensions"]
                rots = annos["rotation_y"]
                gt_names = annos["name"]
                gt_boxes = np.concatenate(
                    [locs, dims, rots[..., np.newaxis]], axis=1
                ).astype(np.float32)
                calib = info["calib"]
                gt_boxes = box_np_ops.box_camera_to_lidar(
                    gt_boxes, calib["R0_rect"], calib["Tr_velo_to_cam"]
                )

                # only center format is allowed. so we need to convert
                # kitti [0.5, 0.5, 0] center to [0.5, 0.5, 0.5]
                box_np_ops.change_box3d_center_(
                    gt_boxes, [0.5, 0.5, 0], [0.5, 0.5, 0.5]
                )

                res["lidar"]["annotations"] = {
                    "boxes": gt_boxes,
                    "names": gt_names,
                }
                res["cam"]["annotations"] = {
                    "boxes": annos["bbox"],
                    "names": gt_names,
                }
        else:
            return NotImplementedError

        return res, info
Exemple #2
0
    def __call__(self, res, info):

        if res["type"] in ["NuScenesDataset", "LyftDataset"
                           ] and "gt_boxes" in info:

            res["lidar"]["annotations"] = {
                "boxes": info["gt_boxes"].astype(np.float32),
                "names": info["gt_names"],
                "tokens": info["gt_boxes_token"],
                "velocities": info["gt_boxes_velocity"].astype(np.float32),
            }
        # True
        elif res["type"] == "KittiDataset":
            # only select useful calib matrix
            calib = info["calib"]
            calib_dict = {
                "rect":
                calib["R0_rect"],
                "Trv2c":
                calib["Tr_velo_to_cam"],
                "P2":
                calib["P2"],
                "frustum":
                box_np_ops.get_valid_frustum(calib["R0_rect"],
                                             calib["Tr_velo_to_cam"],
                                             calib["P2"],
                                             info["image"]["image_shape"]),
            }
            res["calib"] = calib_dict

            if "annos" in info:

                annos = info["annos"]
                # annos = kitti.remove_dontcare_v2(annos)  # todo: try my remove_dontcare_v2 later
                annos = kitti.remove_dontcare(annos)
                locs = annos["location"]  # x, y, z (cam)
                dims = annos["dimensions"]  # l, h, w
                rots = annos[
                    "rotation_y"]  # ry in label file, count from neg y-axis (0 degree), clockwise is postive,
                # anti-clockwise is negative.
                gt_names = annos["name"]
                gt_boxes = np.concatenate([locs, dims, rots[..., np.newaxis]],
                                          axis=1).astype(np.float32)
                calib = info["calib"]

                # x,y,z(cam), l, h, w, ry -> x,y,z(velo), w, l, h, ry
                gt_boxes = box_np_ops.box_camera_to_lidar(
                    gt_boxes, calib["R0_rect"], calib["Tr_velo_to_cam"])
                # real center of gt_boxes_velo: z_value + h/2
                box_np_ops.change_box3d_center_(gt_boxes, [0.5, 0.5, 0],
                                                [0.5, 0.5, 0.5])

                res["lidar"]["annotations"] = {
                    "boxes": gt_boxes,
                    "names": gt_names,
                }  # without difficulty here
                if self.enable_difficulty_level:
                    res["lidar"]["annotations"].update(
                        {"difficulty": annos["difficulty"]})

                res["cam"]["annotations"] = {
                    "boxes": annos["bbox"],
                    "names": gt_names,
                }  # image 2d bbox
        else:
            return NotImplementedError

        return res, info