CameraOpenCVPerspective#

Class Methods

CameraBasePerspective.from_dict(param_dict)

Create a camera model from a parameter dictionary.

Main API Methods

CameraBasePerspective.pixel_image_to_camera_crs(...)

Calculating vectors in camera crs of image points.

CameraBasePerspective.pts_camara_crs_to_image_pixel(...)

Calculating image pixel coordinates of points in camera crs.

CameraBasePerspective.undistorted_to_distorted(...)

Calculating distorted image coordinates from undistorted ones Image points are internally scaled to calibration image size for validity of distortion parameters

CameraBasePerspective.distorted_to_undistorted(...)

Calculating undistorted image coordinates from distorted ones Image points are internally scaled to calibration image size for validity of distortion parameters

additional helpful Methods

CameraBasePerspective.from_dict(param_dict)

Create a camera model from a parameter dictionary.

CameraBasePerspective.undistorted_image_points_inside(...)

Return a mask indicating whether undistorted image points are valid.

CameraBasePerspective.principal_point(image_size)

Return the principal point in the given image size.

CameraBasePerspective._generate_distortion_border([...])

Returns the border of the undistorted image, which is used as border for points which are valid to calculate the distorted ones (The distorted border is the rectangular image itself)

Properties

CameraOpenCVPerspective.param_dict

Return camera parameters as a dictionary.

CameraOpenCVPerspective.type

Return the camera model type.

CameraOpenCVPerspective.focal_length_for_gsd_in_pixel

Returns the focal length in pixel to be used for approximate gsd calculation

CameraOpenCVPerspective.origin

class weitsicht.CameraOpenCVPerspective(*args, **kwargs)[source]#

Bases: CameraBasePerspective

OpenCV perspective (pinhole) camera model.

See also OpenCV calib3d documentation: https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html

__init__(width: int, height: int, fx: float, fy: float, cx: float = 0.0, cy: float = 0.0, k1: float = 0.0, k2: float = 0.0, k3: float = 0.0, k4: float = 0.0, p1: float = 0.0, p2: float = 0.0)[source]#

Initialize an OpenCV pinhole camera model.

Parameters:
  • width (int) – Calibration image width in pixels.

  • height (int) – Calibration image height in pixels.

  • fx (float) – Focal length in x direction in pixels.

  • fy (float) – Focal length in y direction in pixels.

  • cx (float) – Principal point x coordinate in pixels, defaults to 0.0 (interpreted as width/2 - 0.5).

  • cy (float) – Principal point y coordinate in pixels, defaults to 0.0 (interpreted as height/2 - 0.5).

  • k1 (float) – Radial distortion coefficient, defaults to 0.0.

  • k2 (float) – Radial distortion coefficient, defaults to 0.0.

  • k3 (float) – Radial distortion coefficient, defaults to 0.0.

  • k4 (float) – Radial distortion coefficient, defaults to 0.0.

  • p1 (float) – Tangential distortion coefficient, defaults to 0.0.

  • p2 (float) – Tangential distortion coefficient, defaults to 0.0.

Raises:
  • ValueError – If width, height, fx or fy are not positive.

  • TypeError – If any parameter has an incompatible type.

classmethod from_dict(param_dict: dict) CameraOpenCVPerspective[source]#

Create a camera model from a parameter dictionary.

Required keys are: - calib_width - calib_height - fx - fy

Optional keys are: - cx, cy - k1, k2, k3, k4 - p1, p2

Parameters:

param_dict (dict) – Dictionary with camera parameters.

Returns:

Camera model instance.

Return type:

CameraOpenCVPerspective

Raises:
  • KeyError – If required keys are missing.

  • ValueError – If values are invalid (e.g. non-positive dimensions/focal lengths).

  • TypeError – If values have incompatible types.

property type: Literal[CameraType.OpenCV]#

Return the camera model type.

Returns:

Camera model type.

Return type:

CameraType

property param_dict: dict#

Return camera parameters as a dictionary.

The returned dictionary must be compatible with from_dict().

Returns:

Camera parameters.

Return type:

dict

property focal_length_for_gsd_in_pixel: float#

Returns the focal length in pixel to be used for approximate gsd calculation

Returns:

Focal length in pixel.

Return type:

float

property _origin: Vector2D#

Return the origin offset for OpenCV pixel conventions.

OpenCV defines the origin at the center of the top-left pixel, whereas this project uses the top-left pixel edge as (0, 0).

Returns:

Origin offset in pixels.

Return type:

Vector2D

property _principal_point: Vector2D#

principal point in camera size

Returns:

Principal point in camera calibration size.

Return type:

Vector2D

_camara_crs_to_image_crs(pts_camera_crs: ArrayNx3) ArrayNx2[source]#

Project camera CRS coordinates to undistorted image pixel coordinates.

Parameters:

pts_camera_crs (ArrayNx3) – Points in camera CRS.

Returns:

Undistorted image pixel coordinates.

Return type:

ArrayNx2

_image_crs_to_vector_in_camera_crs(pts_image: ArrayNx2) ArrayNx3[source]#

Convert undistorted image pixels to unit vectors in camera CRS.

Parameters:

pts_image (ArrayNx2) – Undistorted image pixel coordinates.

Returns:

Unit direction vectors in camera CRS.

Return type:

ArrayNx3

_to_distorted_points(pts_undistorted_pixel: ArrayNx2) ArrayNx2[source]#

Calculate distorted points from undistorted. Polynomial functions could map extreme outside points inside due too polynom terms. Therefore, we should check for validity first the undistorted points if within border

Parameters:

pts_undistorted_pixel (ArrayNx2) – Undistorted image pixel coordinates.

Returns:

Distorted image pixel coordinates.

Return type:

ArrayNx2

_to_undistorted_points(pts_distorted_pixel: ArrayNx2) ArrayNx2[source]#

Calculate undistorted points from distorted image pixel coordinates.

Parameters:

pts_distorted_pixel (ArrayNx2) – Distorted image pixel coordinates.

Returns:

Undistorted image pixel coordinates.

Return type:

ArrayNx2