model

Core data model and tracking logic for slurpy.

This module isolates the application state (video processing, anchor points history, and active contour tracking) from the GUI, allowing it to be used in headless batch processing.

class SlurpyModel[source]

Bases: object

Manages the video state, tracking history, and snake execution.

Variables:
  • config (super_slurpy.config.SuperSlurpyConfig) – The application configuration.

  • video_path (Path | None) – Path to the loaded video.

  • container (Any | None) – PyAV container.

  • video_stream (Any | None) – The video stream.

  • total_frames (int) – Total number of frames in the video.

  • frame (np.ndarray | None) – The current RGB frame.

  • current_frame_idx (int) – Index of the current frame.

  • anchors (list[list[float]]) – Current active anchors.

  • anchors_history (dict[int, list[list[float]]]) – Dictionary mapping frame index to anchor points.

  • contour (np.ndarray | None) – The interpolated spline for the current anchors.

  • seed_spline (list[list[float]] | None) – The loaded seed spline to apply to new videos.

__init__(config_dir=None)[source]

Initialize the model state.

Parameters:

config_dir (Path | None) – Path to look for configurations. Defaults to None.

load_csv(file_path)[source]

Load history from CSV mapping formats.

Parameters:

file_path (str) – The absolute reading path for extraction.

Return type:

None

Examples

>>> model = SlurpyModel()
>>> model.load_csv(file_path="output.csv")
load_seed_spline_file(file_path)[source]

Load a seed spline from a specific file.

Parameters:

file_path (str) – The target file path.

Raises:

FileNotFoundError – If the target path is not a file.

Return type:

None

Examples

>>> model = SlurpyModel()
>>> model.load_seed_spline_file(file_path="seed.csv")
open_video(file_path)[source]

Open a video and calculate the starting frame based on config.

Parameters:

file_path (str) – The target path of the video file to be loaded.

Returns:

The calculated starting frame index.

Return type:

int

Examples

>>> model = SlurpyModel()
>>> start_idx = model.open_video(file_path="video.mp4")
>>> print(start_idx)
0
read_frame(frame_idx)[source]

Read a specific frame and extract standard RGB formatting.

Parameters:

frame_idx (int) – The absolute frame index to seek and read.

Return type:

None

Examples

>>> model = SlurpyModel()
>>> model.open_video(file_path="video.mp4")
>>> model.read_frame(frame_idx=10)
reset_particle_parameters()[source]

Reset the particle model parameters to the package defaults.

Return type:

None

Examples

>>> model = SlurpyModel()
>>> model.reset_particle_parameters()
reset_snake_parameters()[source]

Reset the active contour parameters to the package defaults.

Return type:

None

Examples

>>> model = SlurpyModel()
>>> model.reset_snake_parameters()
run_particle_tracking(start_idx)[source]

Execute particle filter tracking across the entire video.

Parameters:

start_idx (int) – The index of the frame to begin tracking from.

Yields:

int – The frame index currently being processed.

Examples

>>> model = SlurpyModel()
>>> list(model.run_particle_tracking(start_idx=10))
run_snake_tracking(start_idx)[source]

Run snake tracking forward and backward from a starting frame.

Parameters:

start_idx (int) – The original initialization frame index.

Yields:

int – The frame index currently being processed.

Examples

>>> model = SlurpyModel()
>>> model.anchors = [[0.0, 0.0], [10.0, 10.0]]
>>> list(model.run_snake_tracking(start_idx=0))
save_csv(file_path)[source]

Export history to CSV format.

Parameters:

file_path (str) – The targeted absolute save output path.

Return type:

None

Examples

>>> model = SlurpyModel()
>>> model.anchors_history[0] = [[0.0, 0.0], [10.0, 10.0]]
>>> model.save_csv(file_path="output.csv")
track_current_frame_particle()[source]

Run particle tracking on the current frame only.

Return type:

None

Examples

>>> model = SlurpyModel()
>>> model.track_current_frame_particle()
track_current_frame_snake()[source]

Run snake tracking on the current frame only.

Return type:

None

Examples

>>> model = SlurpyModel()
>>> model.track_current_frame_snake()
update_spline()[source]

Calculate the interpolated contour and auto-save anchors.

Uses PCHIP interpolation for smooth bounds and linear mappings for 2-point arrays. Updates internal contour state.

Return type:

None

Examples

>>> model = SlurpyModel()
>>> model.anchors = [[0.0, 0.0], [10.0, 10.0]]
>>> model.update_spline()