arcjetCV.utils.video
- 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) `
- 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 `
arcjetCV.utils.processor
- class arcjetCV.utils.processor.ArcjetProcessor(videometa)[source]
Bases:
object
Video frame processor
Primary image processing class: used to read in video data, extract leading edges, hold processed arrays, and output processed data to file.
- get_edges_metrics(contour_dict, argdict, offset)[source]
Retrieves edges and metrics from contour dictionary.
- Parameters:
contour_dict – dictionary containing contours
argdict – dictionary containing metrics
offset – tuple containing offset values
- Returns:
edges: dictionary containing edges argdict: updated dictionary containing metrics
- get_flow_direction(frame)[source]
Infers flow direction from the provided frame.
- Parameters:
frame – opencv image
- Returns flowDirection:
string, “left or “right”
TODO: add support for top/bottom directions
- get_image_flags(frame, argdict)[source]
Uses histogram of 8-bit grayscale image (0,255) to classify image type.
- Parameters:
frame – opencv image
argdict – dictionary to store flags
- Returns:
dictionary of flags
- make_crop_square(frame)[source]
Makes the provided frame square by cropping or padding.
- Parameters:
frame – opencv image
- Returns:
square_frame: square opencv image offset: list containing offset values
- process(frame, argdict)[source]
Processes the given frame.
- Parameters:
frame – opencv image
argdict – dictionary containing segmentation parameters
- Returns:
edges: dictionary containing edges argdict: updated dictionary containing metrics
Example:
`python processor = ArcjetProcessor(videometa) frame = cv.imread('frame.jpg') argdict = {"SEGMENT_METHOD": "AutoHSV", "MODEL_FRACTION": 0.005} edges, argdict = processor.process(frame, argdict) `
- process_all(video: Video, options, first_frame, last_frame, frame_stride, output_prefix='', write_json=True, write_video=False, display_shock=True)[source]
Processes all frames in the video.
- Parameters:
video – video object (defined in utils/video.py)
options – dictionary containing segmentation options
first_frame – index of the first frame to process
last_frame – index of the last frame to process
frame_stride – stride for frame processing
write_json – boolean indicating whether to write processed data to JSON file
write_video – boolean indicating whether to write processed video
Example:
`python video = Video('input_video.mp4') options = {"SEGMENT_METHOD": "AutoHSV", "MODEL_FRACTION": 0.005} processor = ArcjetProcessor(videometa) processor.process_all(video, options, 0, 100, 1, 'output.json', write_video=True) `
- segment(img_crop, argdict)[source]
Segments image using one of several methods specified in argdict.
- Parameters:
img_crop – cropped opencv image
argdict – dictionary containing segmentation method and related parameters
- Returns:
contour_dict: dictionary containing contours flags: dictionary containing flags