cvkit.video_readers package
Submodules
cvkit.video_readers.cv2_reader module
- class CV2VideoReader(video_path, fps, buffer_size=64)[source]
Bases:
BaseVideoReaderInterfaceThis implementation uses OpenCV as the underlying library to implement the BaseVideoReaderInterface
- Parameters:
video_path (str) – Path of the video.
fps (float) – The FPS of the video.
buffer_size (int) – The size of the frame pre-fetch buffer.
- FLAVOR = 'opencv'
A unique identifier for BaseVideoReaderInterface Implementation.
- next_frame() ndarray[source]
Returns the next frame from the buffer.
- Returns:
Numpy array representing the newly fetched frame.
- Return type:
Numpy.ndarray
- random_access_image(position)[source]
Fetch frame from the video at random position without affecting the current buffer. It is different from the seek function since it does not reset the internal buffer and does not change the current frame number.
- Parameters:
position (int) – index of the desired frame.
- Returns:
Numpy array representing the newly fetched frame at given position.
- Return type:
Numpy.ndarray
cvkit.video_readers.decord_reader module
cvkit.video_readers.deffcode_reader module
- class DeffcodeVideoReader(video_path, fps, buffer_size=128)[source]
Bases:
BaseVideoReaderInterfaceThis implementation uses Deffcode as the underlying library to implement the BaseVideoReaderInterface.
- Parameters:
video_path (str) – Path of the video.
fps (float) – The FPS of the video.
buffer_size (int) – The size of the frame pre-fetch buffer.
- FLAVOR = 'deffcode'
A unique identifier for BaseVideoReaderInterface Implementation.
- next_frame() ndarray[source]
Returns the next frame from the buffer.
- Returns:
Numpy array representing the newly fetched frame.
- Return type:
Numpy.ndarray
- random_access_image(position)[source]
Fetch frame from the video at random position without affecting the current buffer. It is different from the seek function since it does not reset the internal buffer and does not change the current frame number.
- Parameters:
position (int) – index of the desired frame.
- Returns:
Numpy array representing the newly fetched frame at given position.
- Return type:
Numpy.ndarray
cvkit.video_readers.image_sequence_reader module
- class ImageSequenceReader(video_path, fps, file_formats=['[jJ][pP][gG]', '[pP][nN][gG]', '[bB][mM][pP]'])[source]
Bases:
BaseVideoReaderInterfaceThis implementation interprets a folder of images as a video stream. This can be useful when reading images from the datasets where the videos are stored as individual frames.
- Parameters:
video_path (str) – Path to the folder containing images
fps (float) – FPS of the video stream
file_formats (list[str]) – list of valid glob patterns for supported images.
- FLAVOR = 'Images'
A unique identifier for BaseVideoReaderInterface Implementation.
- next_frame() ndarray[source]
Returns the next frame from the buffer.
- Returns:
Numpy array representing the newly fetched frame.
- Return type:
Numpy.ndarray
- random_access_image(position)[source]
Fetch frame from the video at random position without affecting the current buffer. It is different from the seek function since it does not reset the internal buffer and does not change the current frame number.
- Parameters:
position (int) – index of the desired frame.
- Returns:
Numpy array representing the newly fetched frame at given position.
- Return type:
Numpy.ndarray
cvkit.video_readers.video_reader_interface module
- class BaseVideoReaderInterface(video_path, fps, buffer_size=128)[source]
Bases:
ABCAn interface to provide intuitive access to video data. Users can implement this interface using various underlying video I/O libraries. We provide a few implementations using OpenCV, Deffcode, and Decord.
- Parameters:
video_path (str) – Path of the video.
fps (float) – The FPS of the video.
buffer_size (int) – The size of the frame pre-fetch buffer.
- FLAVOR = 'Abstract'
A unique identifier for BaseVideoReaderInterface Implementation.
- get_current_frame() ndarray[source]
Returns previously fetched frame.
- Returns:
Numpy array representing the frame previously fetched from the buffer.
- Return type:
Numpy.ndarray
- get_current_index() int[source]
Get the frame number of the newest frame fetched from the buffer.
- Returns:
Frame number of current frame.
- Return type:
int
- get_number_of_frames() int[source]
Returns the total number of frames in the video.
- Returns:
Total number of frames.
- Return type:
int
- abstract next_frame() ndarray[source]
Returns the next frame from the buffer.
- Returns:
Numpy array representing the newly fetched frame.
- Return type:
Numpy.ndarray
- abstract random_access_image(position) ndarray[source]
Fetch frame from the video at random position without affecting the current buffer. It is different from the seek function since it does not reset the internal buffer and does not change the current frame number.
- Parameters:
position (int) – index of the desired frame.
- Returns:
Numpy array representing the newly fetched frame at given position.
- Return type:
Numpy.ndarray
Module contents
- initialize_video_reader(video_path, fps, reader_type)[source]
Detects underlying class based on reader_type. And generates appropriate
BaseVideoReaderInterfacesubclass instance.- Parameters:
video_path (str) – Path to the target video file.
fps (float) – The FPS of the video.
reader_type (str) – A string to identify underlying video reader type. Refer to the
FLAVORattributes of each implementation.
- Returns:
BaseVideoReaderInterfacesubclass instance.- Return type: