cv2ext.video package¶
Module contents¶
Utilities for working with videos.
Functions¶
create_timeline()Create a timeline image of a video.
video_from_images()Create a video from a directory of images.
- cv2ext.video.create_timeline(videopath: Path, output: Path | None = None, bboxes: list[tuple[int, int, int, int]] | None = None, offset: int = 20, slices: int = 6, img_size: tuple[int, int] | None = None) np.ndarray[source]¶
Create a timeline image of a video.
- Parameters:
videopath (Path) – Path to the video file.
output (Path, optional) – Path to the output image. If None, the image will not be saved to disk.
bboxes (list[tuple[int, int, int, int]], optional) – List of bounding boxes for each frame.
offset (int, optional) – Number of pixels to offset the bounding boxes.
slices (int, optional) – Number of frames to include in the timeline.
img_size (tuple[int, int], optional) – Size of the images in the timeline.
- Returns:
The timeline image.
- Return type:
np.ndarray
- Raises:
ValueError – If slices and bboxes are not the same length.
- cv2ext.video.video_from_images(directory: Path, output: Path, fps: float = 30.0, extensions: Sequence[str] = ('png', 'jpg', 'jpeg'), fourcc: Fourcc = Fourcc.mp4v) Path[source]¶
Create a video from a directory of images.
The images are assumed to be named such that, when sorted, the video is constructed in the correct order.
- Parameters:
directory (Path) – The directory containing the images.
output (Path) – The output video file. The extension is assumed to match the codec, given by the fourcc parameter.
fps (float) – The frames per second of the video. Defaults to 30.0.
extensions (Sequence[str]) – The extensions of the image files. Defaults to (“png”, “jpg”, “jpeg”). Extensions should not have a dot prefix.
fourcc (Fourcc) – The fourcc codec to use. Defaults to MP4V.
- Returns:
The path to the output video file.
- Return type:
Path