Skip to content

cvtkit.camera

Pose File Formats

Please see the resources page on pose file formats to learn more about the expected/supported formats commonly used in this library.

A suite of common camera utilities.

This module includes several functions for manipulating and extracting information from camera intrinsics and extrinsics, as well as converting between specific formats.

build_o3d_traj(poses, K, width, height)

Converts an array of camera poses and an intrinsics matrix into Open3D trajectory format.

Parameters:

Name Type Description Default
poses ndarray

Nx4x4 array of camera pose in world-to-camera format.

required
K ndarray

3x3 camera intrinsics matrix.

required
width int

Expected image width.

required
height int

Expected image height.

required

Returns:

Type Description
PinholeCameraTrajectory

Open3D camera trajectory model.

camera_center(P)

Computes the center of a camera in world coordinates.

Parameters:

Name Type Description Default
P NDArray[Any] | Tensor

The extrinsics matrix (4x4) of a given camera in world-to-camera format.

required

Returns:

Type Description
NDArray[Any] | Tensor

The camera center vector (3x1) in world coordinates.

compute_baselines(poses)

Computes the minimum and maximum baseline between a reference camera pose (poses[0]) and a cluster of supporting camera poses (poses[1:]).

Parameters:

Name Type Description Default
poses NDArray[Any] | Tensor

Array of camera poses (Nx4x4)

required

Returns:

Type Description
Tuple[float, float]

A tuple of baselines where the first element is the minimum baseline and the second element is the maximum baseline.

crop_intrinsics(K, crop_row, crop_col)

Adjusts intrinsics matrix principle point coordinates corresponding to image cropping.

Parameters:

Name Type Description Default
K NDArray[Any] | Tensor

3x3 camera intrinsics matrix.

required
crop_row int

Offset for cy (corresponding to cropping the left and right side of an image by 'crop_row').

required
crop_col int

Offset for cx (corresponding to cropping the top and bottom side of an image by 'crop_col').

required

Returns:

Type Description
NDArray[Any] | Tensor

The updated 3x3 intrinsics matrix

intrinsic_pyramid(K, levels)

Computes camera intrinsics pyramid corresonding to several levels of image downsampling.

Parameters:

Name Type Description Default
K NDArray[Any] | Tensor

[Batch x 3 x 3] camera intrinsics matrix.

required
levels int

The number of pyramid levels to compute.

required

Returns:

Type Description
NDArray[Any] | Tensor

The intrinsics pyramid of shape [Batch x L x 3 x 3] in descending order.

NDArray[Any] | Tensor

(L=0 corresponds to the largest image resolution).

scale_intrinsics(K, scale)

Adjust intrinsics matrix focal length and principle point corresponding to image scaling.

Parameters:

Name Type Description Default
K NDArray[Any] | Tensor

Batchx3x3 camera intrinsics matrices.

required
scale float

Scale amount (i.e. scale=0.5 corresponds to scaling an image by a factor of 1/2).

required

Returns:

Type Description
NDArray[Any] | Tensor

The updated 3x3 intrinsics matrix.

tensor_null_space(A)

Computes the null space of a PyTorch tensor.

Parameters:

Name Type Description Default
A Tensor

PyTorch tensor of shape m x n.

required

Returns:

Type Description
Tensor

The null space of tensor A.

to_opengl_pose(pose)

OpenGL pose: (right-up-back) (cam-to-world)

Parameters:

Name Type Description Default
pose NDArray[Any] | Tensor

The pose in non-OpenGL format

required

Returns:

Type Description
NDArray[Any] | Tensor

Camera pose in OpenGL format.