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 for reading and extracting data from video files.

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)

  • freq (int, optional) – Frequency to read frames with. Default is 1, if set to e.g. 2 only each 2nd frame will be read.

  • 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) – By default set to True, making frames read in organised chunks. If set to False, video is read in memory entirely. Likely, we will deprecate this option in the future as we plan to optimize chunked reading. Currently if memory size allows, setting lazy to False results in faster processing.

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

  • freq (int, optional) – Frequency to read frames with. Default is 1, if set to e.g. 2 only each 2nd frame will be read.

  • 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) – By default set to True, making frames read in organised chunks. If set to False, video is read in memory entirely. Likely, we will deprecate this option in the future as we plan to optimize chunked reading. Currently if memory size allows, setting lazy to False results in faster processing.

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

get_frames_chunk(n_start, n_end[, method])

Retrieve a chunk of frames in one go.

get_ms(cap[, split])

Get stabilization transforms for each frame based on analysis of stable points outside of water area.

set_mask_from_exterior(exterior)

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

Attributes

camera_config

Get CameraConfig object attached to Video instance.

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

Get frames of Video instance.

freq

Get video sampling frequency.

h_a

Actual water level [m] during video

lazy

Get lazy flag.

mask

Get region mask for stabilization.

rotation

Get rotation code.

stabilize

Get stabilization region coordinates.

start_frame

int, first frame considered in analysis