ParticleDetection.reconstruct_3D.calibrate_cameras

project_points(p_cam1: ndarray, p_cam2: ndarray, calibration: dict, transforms: dict | None = None)[source]

Project points from a stereocamera system to 3D coordinates.

Parameters:
  • p_cam1 (ndarray) – Point coordinates on camera 1. Shape: (2, n)

  • p_cam2 (ndarray) – Point coordinates on camera 2. Shape: (2, n)

  • calibration (dict) –

    Stereocamera calibration parameters with the required fields: "CM1": camera matrix of cam1

    "R": rotation matrix between cam1 & cam2

    "T": translation vector between cam1 & cam2

    "CM2": camera matrix of cam2

  • transforms (dict | None) –

    Coordinate system transformation matrices from camera 1 coordinates to world/experiment coordinates. Must contain the following fields:

    "rotation", "translation"

    Transformation of 3D coordinates to world/experiment coordinates is omitted if transforms is None.

    Default is None.

Returns:

ndarray – 3D point coordinates in either the world/experiment coordinates or camera 1 coordinates, depending on whether transforms is given. Shape: (3, n)

reproject_points(points: ndarray, calibration: dict, transforms: dict | None = None) Tuple[ndarray, ndarray][source]

Project 3D coordinates to 2D stereocamera coordinates.

Parameters:
  • points (np.ndarray) – 3D point coordinates in either the world/experiment coordinates or camera 1 coordinates, depending on whether transforms is given. Shape: (3, n) or (n, 3)

  • calibration (dict) –

    Stereocamera calibration parameters with the required fields:

    "CM1": camera matrix of cam1

    "R": rotation matrix between cam1 & cam2

    "T": translation vector between cam1 & cam2

    "CM2": camera matrix of cam2

  • transforms (dict | None) –

    Coordinate system transformation matrices from camera 1 coordinates to world/experiment coordinates. Must contain the following fields:

    "rotation", "translation"

    Transformation of 3D coordinates from world/experiment coordinates is omitted if transforms is None. Default is None.

Returns:

Tuple[ndarray, ndarray] – 2D image plane coordinates of camera 1 & 2.

stereo_calibrate(cam1_path: str, cam2_path: str, visualize: bool = False)[source]

Calibrate a stereo camera system.

Using images of a checkerboard with 4-by-5 inner corners to calibrate a stereo camera system.

Parameters:
  • cam1_path (str) – Absolute path to a folder containing only the calibration images from camera one.

  • cam2_path (str) – Absolute path to a folder containing only the calibration images from camera two.

  • visualize (bool, optional) –

    Boolean flag to draw corner detection results for camera one images.

    By default False.

    Warning

    This option must be set to False, if the headless version of OpenCV is installed. Otherwise it crashes this function.

Returns:

Tuple – Return values of OpenCV’s stereoCalibrate() function.

[0] : reprojection error

[1] : camera matrix 1

[2] : distortion coefficients 1

[3] : camera matrix 2

[4] : distortion coefficients 2

[5] : rotation matrix (R) -> with T can transform points in camera one’s coordinate system to points in camear two’s coordinate system

[6] : translation vector (T)

[7] : essential matrix (E)

[8] : fundamental matrix (F)