pyorc.Video#

class pyorc.Video(fn: str, camera_config: Optional[Union[str, CameraConfig]] = None, h_a: Optional[float] = None, start_frame: Optional[int] = None, end_frame: Optional[int] = None, freq: Optional[int] = 1, stabilize: Optional[List[List]] = None, lazy: bool = True, rotation: Optional[int] = None, fps: Optional[float] = None)[source]#

Video class, inheriting parts from cv2.VideoCapture. Contains a camera configuration to it, and a start and end frame to read from the video. Several methods read frames into memory or into a xr.DataArray with attributes. These can then be processed with other pyorc API functionalities.

Parameters:
  • fn (str) – Locally stored video file

  • camera_config (pyorc.CameraConfig, optional) – contains all information about the camera, lens parameters, lens position, ground control points with GPS coordinates, and all referencing information (see CameraConfig), needed to reproject frames on a horizontal geographically referenced plane.

  • h_a (float, optional) – actual height [m], measured in local vertical reference during the video (e.g. a staff gauge in view of the camera)

  • start_frame (int, optional) – first frame to use in analysis (default: 0)

  • end_frame (int, optional) – last frame to use in analysis (if not set, last frame available in video will be used)

  • stabilize (list of lists, optional) – set of coordinates, that together encapsulate the polygon that defines the mask, separating land from water. The mask is used to select region (on land) for rigid point search for stabilization. If not set, then no stabilization will be performed

  • lazy (bool, optional) – If set, frames are read lazily. This slows down the processing, but makes interaction with large videos easier and consuming less memory. For operational processing with short videos, it is recommended to set this explicitly to False.

  • rotation (int, optional) – can be 0, 90, 180, 270. If provided, images will be forced to rotate along the provided angle.

  • fps (float, optional) – hard set for frames per second. Use this with utmost caution and only when you are confident that the video metadata is incorrect.

__init__(fn: str, camera_config: Optional[Union[str, CameraConfig]] = None, h_a: Optional[float] = None, start_frame: Optional[int] = None, end_frame: Optional[int] = None, freq: Optional[int] = 1, stabilize: Optional[List[List]] = None, lazy: bool = True, rotation: Optional[int] = None, fps: Optional[float] = None)[source]#

Video class, inheriting parts from cv2.VideoCapture. Contains a camera configuration to it, and a start and end frame to read from the video. Several methods read frames into memory or into a xr.DataArray with attributes. These can then be processed with other pyorc API functionalities.

Parameters:
  • fn (str) – Locally stored video file

  • camera_config (pyorc.CameraConfig, optional) – contains all information about the camera, lens parameters, lens position, ground control points with GPS coordinates, and all referencing information (see CameraConfig), needed to reproject frames on a horizontal geographically referenced plane.

  • h_a (float, optional) – actual height [m], measured in local vertical reference during the video (e.g. a staff gauge in view of the camera)

  • start_frame (int, optional) – first frame to use in analysis (default: 0)

  • end_frame (int, optional) – last frame to use in analysis (if not set, last frame available in video will be used)

  • stabilize (list of lists, optional) – set of coordinates, that together encapsulate the polygon that defines the mask, separating land from water. The mask is used to select region (on land) for rigid point search for stabilization. If not set, then no stabilization will be performed

  • lazy (bool, optional) – If set, frames are read lazily. This slows down the processing, but makes interaction with large videos easier and consuming less memory. For operational processing with short videos, it is recommended to set this explicitly to False.

  • rotation (int, optional) – can be 0, 90, 180, 270. If provided, images will be forced to rotate along the provided angle.

  • fps (float, optional) – hard set for frames per second. Use this with utmost caution and only when you are confident that the video metadata is incorrect.

Methods

__init__(fn[, camera_config, h_a, ...])

Video class, inheriting parts from cv2.VideoCapture.

get_frame(n[, method])

Retrieve one frame.

get_frames([method])

Get a xr.DataArray, containing a dask array of frames, from start_frame until end_frame, expected to be read lazily.

get_ms(cap[, split])

set_mask_from_exterior(exterior)

Prepare a mask grid with 255 outside of the stabilization polygon and 0 inside

Attributes

camera_config

CameraConfig object

corners

list of 4 lists (int) with [column, row] locations of area of interest in video objective

end_frame

int, last frame considered in analysis

fps

float, frames per second

frames

freq

returns: int :rtype: frequency (1 in nth frames to select)

h_a

Actual water level [m] during video

lazy

returns: Mask of region of interest :rtype: np.ndarray

mask

returns: Mask of region of interest :rtype: np.ndarray

rotation

stabilize

start_frame

int, first frame considered in analysis