CameraBasePerspective#
Main API Methods
Calculating vectors in camera crs of image points. |
|
Calculating image pixel coordinates of points in camera crs. |
|
Calculating distorted image coordinates from undistorted ones Image points are internally scaled to calibration image size for validity of distortion parameters |
|
Calculating undistorted image coordinates from distorted ones Image points are internally scaled to calibration image size for validity of distortion parameters |
additional helpful Methods
|
Create a camera model from a parameter dictionary. |
Return a mask indicating whether undistorted image points are valid. |
|
|
Return the principal point in the given image size. |
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
Return camera parameters as a dictionary. |
|
Return the camera model type. |
|
Returns the focal length in pixel to be used for approximate gsd calculation |
|
|
- class weitsicht.CameraBasePerspective(*args, **kwargs)[source]#
Base class for perspective camera models.
This class converts between image pixel coordinates (“image CRS”) and rays in camera coordinates (“camera CRS”). It does not store geo-referencing; world coordinate transforms are handled by the image layer.
Coordinate system conventions: - Image pixel CRS: x points right, y points down (origin at top-left pixel edge). - Camera CRS: x points right, y points up, z points backwards.
Implementations typically apply origin shifts and scale pixel coordinates to a calibration size so that distortion parameters remain valid for resampled images.
Subclasses must implement: - from_dict - type - param_dict - focal_length_for_gsd_in_pixel - _origin - _principal_point - _to_distorted_points - _to_undistorted_points - _image_crs_to_vector_in_camera_crs - _camara_crs_to_image_crs
- __init__(width: int, height: int, pts_distortion: int = 5)[source]#
Initialize a camera perspective model base.
- Parameters:
width (int) – Calibration image width in pixels.
height (int) – Calibration image height in pixels.
pts_distortion (int) – Number of points used to generate the distortion border, defaults to
5.
- abstractmethod classmethod from_dict(param_dict: dict) CameraBasePerspective[source]#
Create a camera model from a parameter dictionary.
- Parameters:
param_dict (dict) – Dictionary as produced by
param_dict.- Returns:
Camera model instance.
- Return type:
- abstract 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
- abstract property type: CameraType#
Return the camera model type.
- Returns:
Camera model type.
- Return type:
CameraType
- abstract 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
- abstract property _origin: Vector2D#
One has to implement the pixel origin of the camera model as offset to the used pixel system. Our system is using the upper left corner as 0,0 For example OpenCVs pixel coordinate system is defined with left upper CENTER is (0,0) therefore we need to apply an offset and return np.array([0.5,0.5])
- Returns:
Origin offset in pixels.
- Return type:
Vector2D
- abstract property _principal_point: Vector2D#
principal point in camera size
- Returns:
Principal point in camera calibration size.
- Return type:
Vector2D
- _generate_distortion_border(points_between: int = 5) ArrayNx2[source]#
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)
- Parameters:
points_between (int) – Number of points between corner points, defaults to
5.- Returns:
ArrayNx2 with the undistorted pixel of the border points
- Return type:
ArrayNx2
- abstractmethod _to_distorted_points(pts_undistorted_pixel: ArrayNx2) ArrayNx2[source]#
function for calculating distorted points from undistorted ones in original calibration image size
- Parameters:
pts_undistorted_pixel (ArrayNx2) – Array of (nx2) with the image coordinates
- Returns:
Array with distorted points
- Return type:
ArrayNx2
- abstractmethod _to_undistorted_points(pts_distorted_pixel: ArrayNx2) ArrayNx2[source]#
function for calculating undistorted points from distorted ones
- Parameters:
pts_distorted_pixel (ArrayNx2) – Array of (nx2) with the image coordinates
- Returns:
ArrayNx2 with undistorted points
- Return type:
ArrayNx2
- abstractmethod _image_crs_to_vector_in_camera_crs(pts_image: ArrayNx2) ArrayNx3[source]#
function for calculating vector in camera crs of undistorted image points
- Parameters:
pts_image (ArrayNx2) – Array of (nx2) with the image coordinates
- Returns:
Array of (Nx3) with vectors of the line of sight of image positions
- Return type:
ArrayNx3
- abstractmethod _camara_crs_to_image_crs(pts_camera_crs: ArrayNx3) ArrayNx2[source]#
function for calculating undistorted points from points in camera crs
- Parameters:
pts_camera_crs (ArrayNx3) – Array of (nx3) with the camera CRS coordinates
- Returns:
Array of size (N,2) with undistorted points
- Return type:
ArrayNx2
- property origin: Vector2D#
- principal_point(image_size: tuple[int, int]) Vector2D[source]#
Return the principal point in the given image size.
- Parameters:
image_size (tuple[int, int]) – Size of the current image (width, height).
- Returns:
Principal point in image pixel CRS.
- Return type:
Vector2D
- _pixel_image_to_calibration_size(pixel_from_image: ArrayNx2, image_size: tuple[int, int]) ArrayNx2[source]#
Calculate scaled image coordinates to calibration size
- Parameters:
pixel_from_image (ArrayNx2) – Array of (nx2) with the image coordinates
image_size (tuple[int, int]) – Size of the current image (width, height).
- Returns:
Array with the image positions scaled to calibration image size
- Return type:
ArrayNx2
- _pixel_calibration_to_image_size(pixel_from_calib_size: ArrayNx2, image_size: tuple[int, int])[source]#
Calculate scaled image coordinates to image file size
- Parameters:
pixel_from_calib_size (ArrayNx2) – Array of (nx2) with the image coordinates
image_size (tuple[int, int]) – Size of the current image (width, height).
- Returns:
Array with the image positions scaled to file image size
- Return type:
ArrayNx2
- undistorted_image_points_inside(points_image_crs: ArrayNx2, image_size: tuple[int, int]) MaskN_[source]#
Return a mask indicating whether undistorted image points are valid.
This takes the distortion border of the camera model into account.
- Parameters:
points_image_crs (ArrayNx2) – Array of (nx2) with image pixel coordinates.
image_size (tuple[int, int]) – Size of the current image (width, height).
- Returns:
Boolean mask of shape (N,).
- Return type:
MaskN_
- pixel_image_to_camera_crs(points_image_crs: ArrayNx2, image_size: tuple[int, int], is_undistorted: bool = False) ArrayNx3[source]#
Calculating vectors in camera crs of image points. Image points are internally scaled to calibration image size for validity of distortion parameters
- Parameters:
points_image_crs (ArrayNx2) – Array of (nx2) with the image coordinates
image_size (tuple[int, int]) – Size of the current image (width, height).
is_undistorted (bool) – Whether input image coordinates are already undistorted, defaults to
False.
- Returns:
Array of size (N,3) with vectors of the line of sight of image positions
- Return type:
ArrayNx3
- pts_camara_crs_to_image_pixel(points_camera_crs: ArrayNx3, image_size: tuple[int, int], to_distorted: bool = True) ArrayNx2[source]#
Calculating image pixel coordinates of points in camera crs. Image points are internally scaled to calibration image size for validity of distortion parameters
- Parameters:
points_camera_crs (ArrayNx3) – Array of (nx3) with the camera crs coordinates
image_size (tuple[int, int]) – Size of the current image (width, height).
to_distorted (bool) – Whether to return distorted image coordinates, defaults to
True.
- Returns:
Array of size (N,2) with pixels in image coordinates. Undistorted or distorted according to_distorted and the camera model used.
- Return type:
ArrayNx2
- distorted_to_undistorted(points_distorted: ArrayNx2, image_size: tuple[int, int]) ArrayNx2[source]#
Calculating undistorted image coordinates from distorted ones Image points are internally scaled to calibration image size for validity of distortion parameters
- Parameters:
points_distorted (ArrayNx2) – Pixel coordinates in pixel CRS
image_size (tuple[int, int]) – Size of the image pts are from (width, height).
- Returns:
Array of size (Nx2) with undistorted image coordinates
- Return type:
ArrayNx2
- undistorted_to_distorted(pts_undistorted: ArrayNx2, image_size: tuple[int, int]) ArrayNx2[source]#
Calculating distorted image coordinates from undistorted ones Image points are internally scaled to calibration image size for validity of distortion parameters
This function does not prove if the undistorted are inside the border of valid pixels
- Parameters:
pts_undistorted (ArrayNx2) – Pixel coordinates in pixel CRS
image_size (tuple[int, int]) – Size of the image pts are from (width, height).
- Returns:
Array of size (Nx2) with distorted image coordinates
- Return type:
ArrayNx2