wed.utils.video_utils module

wed.utils.video_utils.capture2writor(cap: cv2.VideoCapture, out_path: Optional[str] = None, codec: str = 'H264', H: Optional[int] = None, W: Optional[int] = None, fps: Optional[float] = None)Tuple[str, cv2.VideoWriter][source]

Create a suitable cv2.VideoWriter for input cv2.VideoCapture.

Parameters
  • cap (cv2.VideoCapture) – An instance of cv2.VideoCaputure.

  • out_path (Optional[str], optional) – Path to the output video. Defaults to None.

  • codec (str, optional) – Video codec for the output video. Defaults to "H264".

  • H (Optional[int], optional) – Height of the output video. Defaults to None.

  • W (Optional[int], optional) – Width of the output video. Defaults to None.

  • fps (Optional[float], optional) – Frame rate of the output video. Defaults to None.

Returns

Tuple of cv2.VideoWriter and path to output video.

Return type

Tuple[str,cv2.VideoWriter]

Examples

>>> import cv2
>>> from wed.utils import OPENING_TEMPLATE_PATH, capture2writor
>>> cap = cv2.VideoCapture(OPENING_TEMPLATE_PATH)
>>> out, out_path = capture2writor(cap)
>>> isinstance(out, cv2.VideoWriter)
True
wed.utils.video_utils.show_frames(video: Union[str, cv2.VideoCapture], start: int = 0, end: Optional[int] = None, step: int = 1, ncols: int = 6, figsize: Tuple[int, int] = (4, 3), fig: Optional[matplotlib.figure.Figure] = None)matplotlib.figure.Figure[source]

Cut out frames from the video and plot them.

Parameters
  • video (Union[str, cv2.VideoCapture]) – Path to video or an instance of cv2.VideoCaputure.

  • start (int, optional) – Draw subsequent frames from start. Defaults to 0.

  • end (Optional[int], optional) – Draw up to end-th frame. If not specified, draw to the end. Defaults to None.

  • ncols (int, optional) – Number of images lined up side by side (number of columns). Defaults to 6.

  • figsize (Tuple[int, int], optional) – Size of one image. Defaults to (4,3).

  • fig (Optional[Figure], optional) – Figure instance you want to draw in. Defaults to None.

Returns

Figure where frames from start to end are drawn.

Return type

Figure

>>> from wed.utils import show_frames, OPENING_TEMPLATE_PATH
>>> fig = show_frames(video=OPENING_TEMPLATE_PATH, step=30, ncols=4)
>>> fig.show()
_images/wed-utils-video_utils-1.png