kaolin.render.camera¶
Kaolin provides extensive camera API. For an overview, see the Camera class docs.
API¶
Classes¶
Functions¶
- class kaolin.render.camera.CameraFOV(value)¶
Bases:
IntEnum
Camera’s field-of-view can be defined by either of the directions
- DIAGONAL = 2¶
- HORIZONTAL = 0¶
- VERTICAL = 1¶
- kaolin.render.camera.allclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False)¶
This function checks if the camera extrinsics and intrinsics, are close using
torch.allclose()
.- Parameters
- Returns
Result of the comparison
- Return type
(bool)
- kaolin.render.camera.blender_coords()¶
Blender world coordinates are right handed, with the z axis pointing upwards
Z Y ^ / | / |---------> X
- kaolin.render.camera.down_from_homogeneous(homogeneous_vectors)¶
Performs perspective division by dividing each vector by its w coordinate.
Down-projects vectors from 4D homogeneous space to 3D space.
- Parameters
homogenenous_vectors – the inputs vectors, of shape \((..., 4)\)
homogeneous_vectors (Tensor) –
- Returns
the 3D vectors, of same shape than inputs but last dim to be 3
- Return type
- kaolin.render.camera.generate_perspective_projection(fovyangle, ratio=1.0, dtype=torch.float32)¶
Generate perspective projection matrix for a given camera fovy angle.
- kaolin.render.camera.generate_rotate_translate_matrices(camera_position, look_at, camera_up_direction)¶
Generate rotation and translation matrix for given camera parameters.
Formula is \(\text{P_cam} = \text{rot_mtx} * (\text{P_world} - \text{trans_mtx})\)
- Parameters
camera_position (torch.FloatTensor) – camera positions of shape \((\text{batch_size}, 3)\), it means where your cameras are
look_at (torch.FloatTensor) – where the camera is watching, of shape \((\text{batch_size}, 3)\),
camera_up_direction (torch.FloatTensor) – camera up directions of shape \((\text{batch_size}, 3)\), it means what are your camera up directions, generally [0, 1, 0]
- Returns
the camera rotation matrix of shape \((\text{batch_size}, 3, 3)\) and the camera transformation matrix of shape \((\text{batch_size}, 3)\)
- Return type
(torch.FloatTensor, torch.FloatTensor)
- kaolin.render.camera.generate_transformation_matrix(camera_position, look_at, camera_up_direction)¶
Generate transformation matrix for given camera parameters.
Formula is \(\text{P_cam} = \text{P_world} * \text{transformation_mtx}\), with \(\text{P_world}\) being the points coordinates padded with 1.
- Parameters
camera_position (torch.FloatTensor) – camera positions of shape \((\text{batch_size}, 3)\), it means where your cameras are
look_at (torch.FloatTensor) – where the camera is watching, of shape \((\text{batch_size}, 3)\),
camera_up_direction (torch.FloatTensor) – camera up directions of shape \((\text{batch_size}, 3)\), it means what are your camera up directions, generally [0, 1, 0]
- Returns
The camera transformation matrix of shape \((\text{batch_size}, 4, 3)\).
- Return type
(torch.FloatTensor)
- kaolin.render.camera.opengl_coords()¶
Contemporary OpenGL doesn’t enforce specific handedness on world coordinates. However it is common standard to define OpenGL world coordinates as right handed, with the y axis pointing upwards (cartesian):
Y ^ | |---------> X / Z
- kaolin.render.camera.perspective_camera(points, camera_proj)¶
Projects 3D points on 2D images in perspective projection mode.
- Parameters
points (torch.FloatTensor) – 3D points in camera coordinate, of shape \((\text{batch_size}, \text{num_points}, 3)\).
camera_proj (torch.FloatTensor) – projection matrix of shape \((3, 1)\).
- Returns
2D points on image plane of shape \((\text{batch_size}, \text{num_points}, 2)\).
- Return type
(torch.FloatTensor)
- kaolin.render.camera.register_backend(name)¶
Registers a representation backend class with a unique name.
CameraExtrinsics can switch between registered representations dynamically (see
switch_backend()
).- Parameters
name (str) –
- kaolin.render.camera.rotate_translate_points(points, camera_rot, camera_trans)¶
Rotate and translate 3D points on based on rotation matrix and transformation matrix.
Formula is \(\text{P_new} = R * (\text{P_old} - T)\)
- Parameters
points (torch.FloatTensor) – 3D points, of shape \((\text{batch_size}, \text{num_points}, 3)\).
camera_rot (torch.FloatTensor) – rotation matrix, of shape \((\text{batch_size}, 3, 3)\).
camera_trans (torch.FloatTensor) – translation matrix, of shape \((\text{batch_size}, 3, 1)\).
- Returns
3D points in new rotation, of same shape than points.
- Return type
(torch.FloatTensor)
- kaolin.render.camera.up_to_homogeneous(vectors)¶
Up-projects vectors to homogeneous coordinates of four dimensions. If the vectors are already in homogeneous coordinates, this function return the inputs.
- Parameters
vectors (torch.Tensor) – the inputs vectors to project, of shape \((..., 3)\)
- Returns
The projected vectors, of same shape than inputs but last dim to be 4
- Return type