Exemple #1
0
def sampling_points_from_frustum(height,
                                 width,
                                 focal,
                                 principal_point,
                                 depth_min=0.0,
                                 depth_max=5.,
                                 frustum_size=(256, 256, 256)):
    """Generates samples from a camera frustum."""

    # ------------------ Get the rays from the camera ----------------------------
    sampling_points = grid.generate((0., 0.),
                                    (float(width) - 1, float(height) - 1),
                                    (frustum_size[0], frustum_size[1]))
    sampling_points = tf.reshape(sampling_points, [-1, 2])  # [h*w, 2]
    rays = perspective.ray(sampling_points, focal, principal_point)  # [h*w, 3]

    # ------------------ Extract a volume in front of the camera -----------------
    depth_tensor = grid.generate((depth_min, ), (depth_max, ),
                                 (frustum_size[2], ))
    sampling_volume = tf.multiply(tf.expand_dims(
        rays, axis=-1), tf.transpose(depth_tensor))  # [h*w, 3, dstep]
    sampling_volume = tf.transpose(sampling_volume,
                                   [0, 2, 1])  # [h*w, dstep, 3]
    sampling_volume = tf.reshape(sampling_volume, [-1, 3])  # [h*w*dstep, 3]
    return sampling_volume
Exemple #2
0
  def test_ray_project_random(self):
    """Tests that the end point of the ray projects at the good location."""
    tensor_size = np.random.randint(3)
    tensor_shape = np.random.randint(1, 10, size=(tensor_size)).tolist()
    random_point_2d = np.random.normal(size=tensor_shape + [2])
    random_focal = np.random.normal(size=tensor_shape + [2])
    random_principal_point = np.random.normal(size=tensor_shape + [2])

    ray_3d = perspective.ray(random_point_2d, random_focal,
                             random_principal_point)
    point_2d = perspective.project(ray_3d, random_focal, random_principal_point)

    self.assertAllClose(random_point_2d, point_2d, rtol=1e-3)
Exemple #3
0
  def test_project_ray_random(self):
    """Tests that that ray is pointing toward the correct location."""
    tensor_size = np.random.randint(3)
    tensor_shape = np.random.randint(1, 10, size=(tensor_size)).tolist()
    random_point_3d = np.random.normal(size=tensor_shape + [3])
    random_focal = np.random.normal(size=tensor_shape + [2])
    random_principal_point = np.random.normal(size=tensor_shape + [2])
    random_depth = np.expand_dims(random_point_3d[..., 2], axis=-1)

    point_2d = perspective.project(random_point_3d, random_focal,
                                   random_principal_point)
    ray_3d = perspective.ray(point_2d, random_focal, random_principal_point)
    ray_3d = random_depth * ray_3d

    self.assertAllClose(random_point_3d, ray_3d, rtol=1e-3)