config Module

Configuration management for the cat detection recording system.

This module handles loading and accessing configuration from YAML files. It provides getter functions for all configuration values with fallback to hardcoded defaults if the YAML file is missing or invalid.

Configuration is loaded from config.yaml (or a custom path) and can be overridden by command-line arguments in main.py.

Example

Load configuration and get values::

config.initialize_config(Path(“config.yaml”)) threshold = config.get_detection_threshold() output_dir = config.get_output_dir()

config.load_config(config_path: Path) Dict[str, Any][source]

Load configuration from YAML file.

Parameters:

config_path – Path to YAML configuration file

Returns:

Dictionary containing configuration values, or empty dict if loading fails

config.get_config_value(config_data: Dict[str, Any], *keys: str, default: Any = None) Any[source]

Safely get a nested config value.

Parameters:
  • config_data – Configuration dictionary

  • keys – Nested keys to traverse (e.g., ‘detection’, ‘threshold’)

  • default – Default value if key path doesn’t exist

Returns:

Config value or default

config.initialize_config(config_path: Path = PosixPath('config.yaml')) None[source]

Initialize global configuration from YAML file.

Parameters:

config_path – Path to YAML configuration file

config.get_detection_threshold() float[source]

Get detection threshold from config or default.

config.get_model_size() int[source]

Get model size from config or default.

config.get_camera_device() str[source]

Get camera device from config or default.

config.get_fps() int[source]

Get FPS from config or default.

config.get_resolution() Tuple[int, int][source]

Get resolution from config or default.

config.get_record_seconds() int[source]

Get recording duration from config or default.

config.get_output_dir() Path[source]

Get output directory from config or default.

Supports: - Relative paths: “recordings” (relative to current working directory) - Absolute paths: “/home/pi/cat_videos” - Home directory expansion: “~/cat_recordings” (expands to /home/user/cat_recordings)

Returns:

Path object to the output directory

config.get_model_name() str[source]

Get model name from config or default.

config.get_cat_class_id() int[source]

Get cat class ID from config or default.

config.get_camera_controls() Dict[str, Any][source]

Get camera controls from config or empty dict.

Returns:

Dictionary of camera control settings (e.g., ExposureTime, AnalogueGain, AeEnable) Returns empty dict if no controls are configured