arcjetCV.utils.video module

class arcjetCV.utils.video.Video(path)[source]

Bases: object

Convenience wrapper for opencv video capture.

This class provides a simple interface for working with video files using OpenCV. It encapsulates functionality for reading frames from a video file, setting the current frame, and writing processed frames to a new video file.

Attributes:

fpath (str): Path to the video file. name (str): Name of the video file. folder (str): Directory containing the video file. ext (str): Extension of the video file. cap: OpenCV VideoCapture object for reading video frames. nframes (int): Total number of frames in the video. fps (float): Frames per second of the video. shape (tuple): Shape of the video frames (height, width, channels). last_frame: Last frame read from the video. writer: OpenCV VideoWriter object for writing processed frames. _lock: Threading lock for thread-safe access to the video capture object.

Example: `python video = Video('input_video.mp4') print(video) frame = video.get_frame(0) `

close()[source]

Closes the video capture.

close_writer()[source]

Closes the video writer.

get_frame(index)[source]

Retrieves the frame at the specified index.

Parameters:

index – index of the frame to retrieve

Returns:

RGB frame at the specified index

get_next_frame()[source]

Retrieves the next frame from the video.

Returns:

next frame

get_writer(video_output_name)[source]

Initializes the video writer.

set_frame(index)[source]

Sets the frame at the specified index.

Parameters:

index – index of the frame to set

class arcjetCV.utils.video.VideoMeta(video, path)[source]

Bases: dict

Subclass of dictionary designed to save/load video metadata in JSON format.

This class extends the dictionary class to provide functionality for saving and loading video metadata in JSON format. It also includes methods for resetting frame crop parameters and setting frame crop parameters.

Attributes:

folder (str): Directory containing the video metadata file. name (str): Name of the video metadata file. ext (str): Extension of the video metadata file. path (str): Path to the video metadata file.

Example: `python video = Video('input_video.mp4') # load video video_meta = VideoMeta(video, 'metadata.json') # create/load metadata obj video_meta.write() # write metadata to file `

crop_range()[source]

Returns the crop range.

load(path)[source]

Loads metadata from a JSON file.

Parameters:

path – path to the JSON file

reset_frame_crop()[source]

Resets frame crop parameters to defaults.

set_frame_crop(ymin, ymax, xmin, xmax)[source]

Sets frame crop parameters.

Parameters:
  • ymin – minimum y coordinate

  • ymax – maximum y coordinate

  • xmin – minimum x coordinate

  • xmax – maximum x coordinate

write()[source]

Writes the metadata to a JSON file.