pyorc.CameraConfig#

class pyorc.CameraConfig(height: int, width: int, crs: Optional[Any] = None, window_size: int = 10, resolution: float = 0.05, bbox: Optional[Union[Polygon, str]] = None, camera_matrix: Optional[List[List[float]]] = None, dist_coeffs: Optional[List[List[float]]] = None, lens_position: Optional[List[float]] = None, corners: Optional[List[List[float]]] = None, gcps: Optional[Dict[str, Union[List, float]]] = None, lens_pars: Optional[Dict[str, float]] = None, calibration_video: Optional[str] = None, is_nadir: Optional[bool] = False, stabilize: Optional[List[List]] = None, rotation: Optional[int] = None)[source]#

Camera configuration containing information about the perspective of the camera.

The camera configuration contains information and functionalities to reconstruct perspective information relating 2D image coordinates to 3D real world coordinates.

Initialize a camera configuration instance.

Parameters:
  • height (int) – height of frame in pixels

  • width (int) – width of frame in pixels

  • crs (int, dict or str, optional) – Coordinate Reference System. Accepts EPSG codes (int or str) proj (str or dict) or wkt (str). Only used if the data has no native CRS.

  • window_size (int) – pixel size of interrogation window (default: 15)

  • resolution (float, optional) – resolution in m. of projected pixels (default: 0.01)

  • bbox (shapely.geometry.Polygon, optional) – bounding box in geographical coordinates

  • camera_matrix (List[List[float]], optional) – pre-defined camera matrix (if e.g. known from a separate calibration)

  • dist_coeffs (List[List[float]], optional) – pre-defined distortion parameters (if e.g. known from a separate calibration)

  • lens_position (list of floats (3),) – x, y, z coordinate of lens position in CRS

  • corners (list of lists of floats (2)) – [x, y] coordinates defining corners of area of interest in camera cols/rows, bbox will be computed from this

  • gcps (dict) – Can contain “src”: list of lists, with column, row locations in objective of control points, “dst”: list of lists, with x, y or x, y, z locations (local or global coordinate reference system) of control points, “h_ref”: float, measured water level [m] in local reference system (e.g. from staff gauge or pressure gauge) during gcp survey, “z_0”: float, water level [m] in global reference system (e.g. from used GPS system CRS). This must be in the same vertical reference as the measured bathymetry and other survey points, “crs”: int, str or CRS object, CRS in which “dst” points are measured. If None, a local coordinate system is assumed (e.g. from spirit level).

  • lens_pars (dict, optional) – Lens parameters, containing: “k1”: float, barrel lens distortion parameter (default: 0.), “c”: float, optical center (default: 2.), “focal_length”: float, focal length (default: width of image frame)

  • calibration_video (str, optional) – local path to video file containing a checkerboard pattern. Must be 9x6 if called directly, otherwise use .calibrate_camera explicitly and provide chessboard_size explicitly. When used, an automated camera calibration on the video file will be attempted.

  • is_nadir (bool, optional) – If set, the video is assumed to be taken at sub-drone position and only two control points are needed for camera configuration

  • stabilize (list (of lists), optional) – contains [x, y] pixels defining a polygon enclosing moving (water) areas. Areas outside of the polygon are used for stabilization of the video, if this polygon is defined.

  • rotation (int [90, 180, 270]) – enforces a rotation of the video of 90, 180 or 2780 degrees clock-wise.

__init__(height: int, width: int, crs: Optional[Any] = None, window_size: int = 10, resolution: float = 0.05, bbox: Optional[Union[Polygon, str]] = None, camera_matrix: Optional[List[List[float]]] = None, dist_coeffs: Optional[List[List[float]]] = None, lens_position: Optional[List[float]] = None, corners: Optional[List[List[float]]] = None, gcps: Optional[Dict[str, Union[List, float]]] = None, lens_pars: Optional[Dict[str, float]] = None, calibration_video: Optional[str] = None, is_nadir: Optional[bool] = False, stabilize: Optional[List[List]] = None, rotation: Optional[int] = None)[source]#

Initialize a camera configuration instance.

Parameters:
  • height (int) – height of frame in pixels

  • width (int) – width of frame in pixels

  • crs (int, dict or str, optional) – Coordinate Reference System. Accepts EPSG codes (int or str) proj (str or dict) or wkt (str). Only used if the data has no native CRS.

  • window_size (int) – pixel size of interrogation window (default: 15)

  • resolution (float, optional) – resolution in m. of projected pixels (default: 0.01)

  • bbox (shapely.geometry.Polygon, optional) – bounding box in geographical coordinates

  • camera_matrix (List[List[float]], optional) – pre-defined camera matrix (if e.g. known from a separate calibration)

  • dist_coeffs (List[List[float]], optional) – pre-defined distortion parameters (if e.g. known from a separate calibration)

  • lens_position (list of floats (3),) – x, y, z coordinate of lens position in CRS

  • corners (list of lists of floats (2)) – [x, y] coordinates defining corners of area of interest in camera cols/rows, bbox will be computed from this

  • gcps (dict) – Can contain “src”: list of lists, with column, row locations in objective of control points, “dst”: list of lists, with x, y or x, y, z locations (local or global coordinate reference system) of control points, “h_ref”: float, measured water level [m] in local reference system (e.g. from staff gauge or pressure gauge) during gcp survey, “z_0”: float, water level [m] in global reference system (e.g. from used GPS system CRS). This must be in the same vertical reference as the measured bathymetry and other survey points, “crs”: int, str or CRS object, CRS in which “dst” points are measured. If None, a local coordinate system is assumed (e.g. from spirit level).

  • lens_pars (dict, optional) – Lens parameters, containing: “k1”: float, barrel lens distortion parameter (default: 0.), “c”: float, optical center (default: 2.), “focal_length”: float, focal length (default: width of image frame)

  • calibration_video (str, optional) – local path to video file containing a checkerboard pattern. Must be 9x6 if called directly, otherwise use .calibrate_camera explicitly and provide chessboard_size explicitly. When used, an automated camera calibration on the video file will be attempted.

  • is_nadir (bool, optional) – If set, the video is assumed to be taken at sub-drone position and only two control points are needed for camera configuration

  • stabilize (list (of lists), optional) – contains [x, y] pixels defining a polygon enclosing moving (water) areas. Areas outside of the polygon are used for stabilization of the video, if this polygon is defined.

  • rotation (int [90, 180, 270]) – enforces a rotation of the video of 90, 180 or 2780 degrees clock-wise.

Methods

__init__(height, width[, crs, window_size, ...])

Initialize a camera configuration instance.

estimate_lens_position()

Estimate lens position from distortion and intrinsec/extrinsic matrix.

get_M([h_a, to_bbox_grid, reverse])

Establish a transformation matrix for a certain actual water level h_a.

get_bbox([camera, h_a, z_a, within_image, ...])

Get bounding box.

get_camera_coords(points)

Convert real-world coordinates into camera coordinates.

get_depth(z[, h_a])

Retrieve depth for measured bathymetry points.

get_dist_shore(x, y, z[, h_a])

Retrieve depth for measured bathymetry points.

get_dist_wall(x, y, z[, h_a])

Retrieve distance to wall for measured bathymetry points.

get_z_a([h_a])

Get actual water level measured in global vertical datum (+z_0) from water level in local datum (+h_ref).

h_to_z(h_a)

Convert z coordinates of bathymetry to height coordinates in local reference (e.g.

plot([figsize, ax, tiles, buffer, ...])

Plot geographical situation of the CameraConfig.

plot_bbox([ax, camera, transformer, h_a, ...])

Plot bounding box.

project_grid(xs, ys, zs[, swap_y_coords])

Project gridded coordinates to col, row coordinates on image.

project_points(points[, within_image, ...])

Project real world x, y, z coordinates into col, row coordinates on image.

set_bbox_from_corners(corners)

Establish bbox based on a set of camera perspective corner points.

set_gcps(src, dst, z_0[, h_ref, crs])

Set ground control points for the given CameraConfig.

set_intrinsic([camera_matrix, dist_coeffs, ...])

Set lens and distortion parameters.

set_lens_calibration(fn[, chessboard_size, ...])

Calibrate and set the properties camera_matrix and dist_coeffs using a video of a chessboard pattern.

set_lens_pars([k1, c, focal_length])

Set the lens parameters of the given CameraConfig.

set_lens_position(x, y, z[, crs])

Set the geographical position of the lens of current CameraConfig.

to_dict()

Return the CameraConfig object as dictionary.

to_dict_str()

Convert the current instance to a dictionary with all values converted to strings.

to_file(fn)

Write the CameraConfig object to json structure.

to_json()

Convert CameraConfig object to string.

unproject_points(points, zs)

Reverse projects points in [column, row] space to [x, y, z] real world.

z_to_h(z)

Convert z coordinates of bathymetry to height coordinates in local reference (e.g.

Attributes

bbox

Give geographical bbox fitting around corners points of area of interest in camera perspective.

camera_matrix

Get camera matrix.

dist_coeffs

Get distortion coefficients.

gcps_bbox_reduced

Give col, row coordinates of gcps within intended bounding box, reduced by mean coordinate.

gcps_dest

Get destination coordinates of GCPs.

gcps_dest_bbox

Give destination coordinates as row, col in intended bounding box.

gcps_dims

Return amount of dimensions of GCPs provided (2 or 3).

gcps_mean

Get mean location of gcp destination points.

gcps_reduced

Get location of gcp destination points, reduced with their mean for better local projection.

is_nadir

Return if the camera configuration belongs to nadir video.

pnp

Return Precise N point solution from ground control points, intrinsics and distortion.

rotation

Return rotation OpenCV code.

shape

Return rows and columns in projected frames from Frames.project.

stabilize

Return stabilization polygon (anything outside is used for stabilization.

transform

Returns Affine transform of projected frames from Frames.project.