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 with respect to real world coordinates

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

  • 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).

  • (deprecated) (lens_pars) – 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]#
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

  • 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).

  • (deprecated) (lens_pars) – 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, ...])

param height:

height of frame in pixels

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, ...])

param camera:

If set, the bounding box will be returned as row and column coordinates in the camera perspective.

get_camera_coords(points)

Convert real-world coordinates into camera coordinates using :param points: [x, y, z] real-world coordinates :type points: array-like list (of lists)

get_depth(z[, h_a])

Retrieve depth for measured bathymetry points using the camera configuration and an actual water level, measured in local reference (e.g.

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

Retrieve depth for measured bathymetry points using the camera configuration and an actual water level, measured in local reference (e.g.

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

Retrieve distance to wall for measured bathymetry points using the camera configuration and an actual water level, measured in local reference (e.g.

get_z_a([h_a])

h_a : float, optional

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

Plot the geographical situation of the CameraConfig.

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

Plot bounding box for orthorectification in a geographical projection (camera=False) or the camera Field Of View (camera=True).

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 Assign corner coordinates to camera configuration

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_calibration(fn[, chessboard_size, ...])

Calibrates and sets 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()

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 :param points: Points in [col, row] to unproject :type points: List of lists or array-like :param zs: :type zs: float or list of floats : z-coordinate on which to unproject points

z_to_h(z)

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

Attributes

bbox

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

camera_matrix

dist_coeffs

gcps_bbox_reduced

returns: dst -- Destination coordinates in col, row in the intended bounding box, reduced with their mean coordinate :rtype: np.ndarray

gcps_dest

returns: dst -- destination coordinates of ground control point.

gcps_dest_bbox

returns: dst -- Destination coordinates measured as column, row in the intended bounding box with the intended resolution :rtype: np.ndarray

gcps_dims

returns: dims -- amount of dimensions of gcps (can be 2 or 3) :rtype: int

gcps_mean

Get the mean location of gcp destination points

gcps_reduced

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

is_nadir

Returns if the camera configuration belongs to nadir video

pnp

rotation

Return rotation OpenCV code

shape

Returns 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