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, calibration_video: Optional[str] = None, is_nadir: Optional[bool] = False, stabilize: Optional[List[List]] = None, rotation: Optional[int] = None, rvec: Optional[List[float]] = None, tvec: Optional[List[float]] = 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). 
- calibration_video (str, optional) – local path to video file containing a checkerboard pattern. Must be 9x6 if called directly, otherwise use - .calibrate_cameraexplicitly and provide- chessboard_sizeexplicitly. 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. 
- rvec (list of floats (3), optional) – OpenCV compatible rotation vector, if known. If None, the rotation will be computed from pnp solving if gcps are available. 
- tvec (list of floats (3), optional) – OpenCV compatible translation vector, if known. If None, the rotation will be computed from pnp solving if gcps are available. 
 
 - __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, calibration_video: Optional[str] = None, is_nadir: Optional[bool] = False, stabilize: Optional[List[List]] = None, rotation: Optional[int] = None, rvec: Optional[List[float]] = None, tvec: Optional[List[float]] = 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). 
- calibration_video (str, optional) – local path to video file containing a checkerboard pattern. Must be 9x6 if called directly, otherwise use - .calibrate_cameraexplicitly and provide- chessboard_sizeexplicitly. 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. 
- rvec (list of floats (3), optional) – OpenCV compatible rotation vector, if known. If None, the rotation will be computed from pnp solving if gcps are available. 
- tvec (list of floats (3), optional) – OpenCV compatible translation vector, if known. If None, the rotation will be computed from pnp solving if gcps are available. 
 
 
 - Methods - __init__(height, width[, crs, window_size, ...])- Initialize a camera configuration instance. - calibrate()- Calibrate camera parameters using ground control. - 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, mode, h_a, z_a, ...])- Get bounding box. - 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_extrinsic()- Return rotation and translation vector based on control points and intrinsic parameters. - 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. - map_idx_img_ortho(x, y, z)- Map pixel indices from the image to an orthographic projection for nearest resampling. - map_mean_idx_img_ortho(x, y, z)- Map pixel indices from the image to an orthographic projection for mean resampling. - plot([figsize, ax, tiles, buffer, ...])- Plot geographical situation of the CameraConfig. - plot_3d_pose([ax, length])- Plot 3D pose of a camera using its rotation and translation vectors. - plot_bbox([ax, camera, mode, transformer, ...])- 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. - rotate_translate_bbox([angle, xoff, yoff])- Rotate and translate the bounding box. - set_bbox_from_corners(corners)- Establish bbox based on a set of camera perspective corner points. - set_bbox_from_width_length(points)- Establish bbox based on three provided points. - set_gcps(src, dst, z_0[, h_ref, crs])- Set ground control points for the given CameraConfig. - 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_position(x, y, z[, crs])- Set the geographical position of the lens of current CameraConfig. - to_dict()- Return the CameraConfig object as dictionary. - 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 - Give geographical bbox fitting around corners points of area of interest in camera perspective. - camera_matrix- Get camera matrix. - dist_coeffs- Get distortion coefficients. - focal_length- Get focal length. - 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. - k1- Get first distortion coefficient. - k2- Get second distortion coefficient. - pnp- Return Precise N point solution from ground control points, intrinsics and distortion. - rotation- Return rotation OpenCV code. - rvec- Return rvec from precise N point solution. - Return rows and columns in projected frames from Frames.project. - stabilize- Return stabilization polygon (anything outside is used for stabilization. - Returns Affine transform of projected frames from Frames.project. - tvec- Return tvec from precise N point solution.