예제 #1
0
 def testKITTIObjToBBoxAndInverse(self):
     objects = kitti_data.LoadLabelFile(self._label_file)
     calib = kitti_data.LoadCalibrationFile(self._calib_file)
     for obj in objects:
         bbox3d = kitti_data._KITTIObjectToBBox3D(
             obj, kitti_data.CameraToVeloTransformation(calib))
         location, dimensions, rotation_y = kitti_data.BBox3DToKITTIObject(
             bbox3d, kitti_data.VeloToCameraTransformation(calib))
         self.assertAllClose(obj['location'], location)
         self.assertAllClose(obj['dimensions'], dimensions)
         self.assertAllClose(obj['rotation_y'], rotation_y)
예제 #2
0
    def testVeloToImagePlaneTransformation(self):
        objects = kitti_data.LoadLabelFile(self._label_file)
        calib = kitti_data.LoadCalibrationFile(self._calib_file)

        # Only apply to object 0.
        obj = objects[0]
        bbox3d = kitti_data._KITTIObjectToBBox3D(
            obj, kitti_data.CameraToVeloTransformation(calib))

        # Convert to corners in our canonical space.
        corners = geometry.BBoxCorners(
            tf.constant([[bbox3d]], dtype=tf.float32))
        with self.session():
            corners_np = self.evaluate(corners)
        corners_np = corners_np.reshape([8, 3])

        # Add homogenous coordinates.
        corners_np = np.concatenate([corners_np, np.ones((8, 1))], axis=-1)

        # Apply the velo to image plane transformation.
        velo_to_img = kitti_data.VeloToImagePlaneTransformation(calib)
        corners_np = np.dot(corners_np, velo_to_img.T)

        # Divide by the last coordinate to recover pixel locations.
        corners_np[:, 0] /= corners_np[:, 2]
        corners_np[:, 1] /= corners_np[:, 2]

        # Obtain 2D bbox.
        min_x = np.min(corners_np[:, 0])
        max_x = np.max(corners_np[:, 0])
        min_y = np.min(corners_np[:, 1])
        max_y = np.max(corners_np[:, 1])
        bbox = [min_x, min_y, max_x, max_y]  # left, top, right, bottom.

        # This should correspond to the GT bbox in obj['bbox'].
        # We use atol=0.1 here since they should close to the nearest pixel.
        self.assertAllClose(bbox, obj['bbox'], atol=0.1)