Video¶
Interface to support treating videos like arrays using OpenCV
- pydantic model VideoJsonDict[source]¶
Json-able roundtrip representation of a video file
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Fields:
- to_array_input() VideoProxy[source]¶
Construct a
VideoProxy
- class VideoProxy(path: Path | None = None, video: VideoCapture | None = None)[source]¶
Passthrough proxy class to interact with videos as arrays
- property video: VideoCapture¶
Opened video capture object
- property sample_frame: ndarray¶
A stored frame from the video to use when calculating shape and dtype
- property shape: tuple[int, ...]¶
Shape of video like
(n_frames, height, width, channels)Note that this order flips the order of height and width from typical resolution specifications: eg. 1080p video is typically 1920x1080, but here it would be 1080x1920. This follows opencv’s ordering, which matches expectations when eg. an image is read and plotted with matplotlib: the first index is the position in the 0th dimension - the height, or “y” axis - and the second is the width/x.
- property n_frames: int¶
Try to get number of frames using opencv metadata, and manually count if no t
- __eq__(other: VideoProxy) bool[source]¶
Check if this is a proxy to the same video file
- class VideoInterface(shape: tuple[int, ...] | Any = typing.Any, dtype: str | type | Any | generic = typing.Any)[source]¶
OpenCV interface to treat videos as arrays.
- return_type¶
alias of
VideoProxy
- json_model¶
alias of
VideoJsonDict
- classmethod check(array: Any) bool[source]¶
Check if array is a string or Path with a supported video extension, or an opened VideoCapture object
- before_validation(array: Any) VideoProxy[source]¶
Get a
VideoProxyobject for this video
- classmethod to_json(array: VideoProxy, info: SerializationInfo) list | VideoJsonDict[source]¶
Return a json-representation of a video