A camera file with a range of functions to handle the camera and it's coordinates.

normalize_screen_coordinates[source]

normalize_screen_coordinates(X, w, h)

Normalize so that [0, w] is mapped to [-1, 1], while preserving the aspect ratio.

def normalize_screen_coordinates(X, w, h): 
    """
    Normalize so that [0, w] is mapped to [-1, 1], while preserving the 
    aspect ratio.
    """
    assert X.shape[-1] == 2
    
    return 2*(X/w) - [1, h/w]

image_coordinates[source]

image_coordinates(X, w, h)

Return the image coordinates

def image_coordinates(X, w, h):
    """Return the image coordinates"""
    assert X.shape[-1] == 2
    # Reverse camera frame normalization
    return (X + [1, h/w])*w/2

world_to_camera[source]

world_to_camera(X, R, t)

Converts from world to camera coordinates with Human3.6M extrinsic camera parameters structure.

camera_to_world[source]

camera_to_world(X, R, t)

Converts from camera to world coordinates with Human3.6M extrinsic camera parameters structure.

project_to_2d[source]

project_to_2d(X, camera_params)

Project 3D points to 2D using the Human3.6M camera projection function. This is a differentiable and batched reimplementation of the original MATLAB script.

Arguments: X -- 3D points in camera space to transform (N, *, 3) camera_params -- intrinsic parameteres (N, 2+2+3+2=9)

project_to_2d_linear[source]

project_to_2d_linear(X, camera_params)

Project 3D points to 2D using only linear parameters (focal length and principal point).

Arguments: X -- 3D points in camera space to transform (N, *, 3) camera_params -- intrinsic parameteres (N, 2+2+3+2=9)

Miqus Camera

Functions that handles extrinsic camera parameters from Qualisys calibration file

world_to_camera_miqus[source]

world_to_camera_miqus(P, R, T)

Convert points from world to camera coordinates Args P: Nx3 3d points in world coordinates R: 3x3 Camera rotation matrix T: 3x1 Camera translation parameters Returns X_cam: Nx3 3d points in camera coordinates

def world_to_camera_miqus(P, R, T):
  """
  Convert points from world to camera coordinates
  Args
    P: Nx3 3d points in world coordinates
    R: 3x3 Camera rotation matrix
    T: 3x1 Camera translation parameters
  Returns
    X_cam: Nx3 3d points in camera coordinates
  """

  assert len(P.shape) == 2
  assert P.shape[1] == 3

  X_cam = R.dot( P.T - T ) # rotate and translate

  return X_cam.T

camera_to_world_miqus[source]

camera_to_world_miqus(P, R, T)

Inverse of world_to_camera_frame Args P: Nx3 points in camera coordinates R: 3x3 Camera rotation matrix T: 3x1 Camera translation parameters Returns X_cam: Nx3 points in world coordinates

def camera_to_world_miqus(P, R, T):
  """Inverse of world_to_camera_frame
  Args
    P: Nx3 points in camera coordinates
    R: 3x3 Camera rotation matrix
    T: 3x1 Camera translation parameters
  Returns
    X_cam: Nx3 points in world coordinates
  """

  assert len(P.shape) == 2
  assert P.shape[1] == 3

  X_cam = R.T.dot( P.T ) + T # rotate and translate

  return X_cam.T

project_point_radial[source]

project_point_radial(P, R, T, f, c, k, p)

Project points from 3d to 2d using camera parameters including radial and tangential distortion Args P: Nx3 points in world coordinates R: 3x3 Camera rotation matrix T: 3x1 Camera translation parameters f: (scalar) Camera focal length c: 2x1 Camera center k: 3x1 Camera radial distortion coefficients p: 2x1 Camera tangential distortion coefficients Returns Proj: Nx2 points in pixel space D: 1xN depth of each point in camera space radial: 1xN radial distortion per point tan: 1xN tangential distortion per point r2: 1xN squared radius of the projected points before distortion