Camera#

class deltacamera.Camera(optical_center=None, rot_world_to_cam=None, intrinsic_matrix=None, distortion_coeffs=None, world_up=(0, 0, 1), extrinsic_matrix=None, trans_after_rot=None, image_shape=None, image_size=None, distortion_model=None)[source]#

Pinhole camera with extrinsic and intrinsic calibration with optional distortions.

The camera coordinate system has the following axes:

x points to the right y points down z points forwards

The world z direction is assumed to point up by default, but world_up can also be

specified differently.

Parameters:
  • optical_center – position of the camera in world coordinates (eye point)

  • rot_world_to_cam – 3x3 rotation matrix for transforming column vectors from being expressed in world reference frame to being expressed in camera reference frame as follows: column_point_cam = rot_matrix_world_to_cam @ (column_point_world - optical_center)

  • intrinsic_matrix – 3x3 matrix that maps 3D points in camera space to homogeneous coordinates in image (pixel) space. Its last row must be (0,0,1).

  • distortion_coeffs – parameters describing radial and tangential lens distortions, following OpenCV’s model and order: k1, k2, p1, p2, k3 or None, if the camera has no distortion.

  • world_up – a world vector that is designated as “pointing up”.

  • extrinsic_matrix – 4x4 extrinsic transformation matrix as an alternative to providing optical_center and rot_world_to_cam.

  • trans_after_rot – translation vector to apply after the rotation (alternative to optical_center, which is a negative translation before the rotation)

  • distortion_model (Optional[LensDistortionModel])

Properties#

distortion_model

The lens distortion model, or None if undistorted.

distortion_coeffs

Get the raw distortion coefficients (deprecated).

image_shape

Image shape as (height, width) tuple, or None if not set.

optical_center

The optical center (position) of the camera.

Instance Methods#

camera_to_image(points[, validate_distortion, dst])

Transform points from 3D camera coordinate space to image space.

world_to_camera(points)

Transform points from world coordinate space to camera coordinate space.

camera_to_world(points)

Transform points from camera coordinate space to world coordinate space.

world_to_image(points[, validate_distortion])

Transform points from world coordinate space to image space.

image_to_camera(points[, depth, validate_distortion, dst])

Transform points from image space to camera space.

image_to_world(points[, camera_depth])

Transform points from image space to world space.

is_visible(world_points, imsize[, validate_distortion])

Check if points in world coordinates are visible in the image.

shift_image(offset)

Adjust intrinsics so that the projected image is shifted by offset.

shift_to_desired(current_coords_of_the_point, ...)

Shift the principal point to move a specific point to a desired location in the image.

reset_roll()

Roll the camera upright by turning along the optical axis to align the vertical image

orbit_around(world_point_pivot, angle_radians[, axis])

Rotate the camera around a vertical or horizontal axis passing through world point by

rotate([yaw, pitch, roll])

Rotate this camera by yaw, pitch, roll Euler angles in radians,

rotate_image(angle[, imshape, anchor])

Transform the camera such that the produces image will be rotated around its center

has_fisheye_distortion()

Check if the camera has fisheye (Kannala-Brandt) distortion.

has_nonfisheye_distortion()

Check if the camera has non-fisheye (Brown-Conrady) distortion.

zoom(factor)

Zooms the camera (factor > 1 makes objects look larger),

scale_output(factor)

Adjusts the camera such that the images become scaled by factor. It's a scaling with

undistort([alpha_balance, imshape, new_imshape, ...])

Undistort the camera by removing lens distortion and optionally adjusting the intrinsic

square_pixels()

Adjusts the intrinsic matrix such that the pixels correspond to squares on the

horizontal_flip()

Flip the camera horizontally by negating the first row of the rotation matrix.

horizontal_flip_image(imshape)

Flip the camera horizontally by negating the first row of the rotation matrix,

center_principal_point(imshape)

Adjusts the intrinsic matrix so that the principal point becomes located at the center

shift_to_center(desired_center_image_point, imshape)

Shifts the principal point such that what's currently at desired_center_image_point

turn_towards([target_image_point, target_world_point, ...])

Turns the camera so that its optical axis goes through a desired target point.

get_projection_matrix()

Get the 3x4 projection matrix that maps 3D points in camera space to homogeneous

get_extrinsic_matrix()

Get the 4x4 extrinsic transformation matrix that maps 3D points in world space to

get_inv_extrinsic_matrix()

Get the 4x4 extrinsic transformation matrix that maps 3D points in camera space to

get_fov(imshape)

Get the field of view of the camera in degrees.

get_distortion_coeffs([n_coeffs_min, n_coeffs_max])

Get the distortion coefficients of the camera, padded or truncated as needed.

has_distortion()

Check if the camera has nonzero lens distortion.

allclose(other_camera)

Check if all parameters of this camera are close to corresponding parameters

is_equal(other)

Check if all parameters are exactly equal to another camera.

__hash__()

Hash based on all camera parameters for use as dict key.

__eq__(other)

Compare cameras for equality based on all parameters.

__setstate__(state)

Wrap arrays as DeprecatingArray after unpickling and handle legacy pickles.

copy(*[, intrinsic_matrix, rot_world_to_cam, R, ...])

Create a copy of this camera, optionally with modified parameters.

zoomed(factor)

Return a new camera with focal length scaled by factor.

rotated([yaw, pitch, roll])

Return a new camera rotated by yaw, pitch, roll Euler angles in radians.

turned_towards([target_image_point, ...])

Return a new camera with optical axis pointing at a target point.

orbited_around(world_point, angle[, axis])

Return a new camera orbited around a world point.

rolled_upright()

Return a new camera rolled upright to align with world up vector.

hflipped()

Return a new camera with horizontal flip (negated first row of rotation).

image_shifted(offset)

Return a new camera with principal point shifted by offset.

point_shifted_to(current_point, target_point)

Return a new camera with principal point adjusted to move a point.

point_shifted_to_center(point)

Return a new camera with principal point adjusted so that point appears at the

image_cropped(new_shape[, anchor])

Return a camera adjusted for a cropped image.

image_padded(new_shape[, anchor])

Return a camera adjusted for a padded image.

image_resized(new_shape)

Return a camera adjusted for a resized image.

image_scaled(factor[, center_subpixels])

Return a camera adjusted for a uniformly scaled image.

image_hflipped()

Return a camera adjusted for a horizontally flipped image.

image_rotated(angle[, anchor])

Return a camera adjusted for a rotated image.

image_rot90([k])

Return a camera adjusted for a 90-degree rotated image.

undistorted([square_pixels, zero_skew])

Return a new camera with distortion removed.

principal_point_centered()

Return a new camera with principal point at image center.

Static Methods#

from_fov(fov_degrees, imshape[, world_up, side])

Create a camera with a given field of view, with centered principal point.

create2D([imshape])

Create a camera for expressing 2D transformations by using intrinsics only.