Skip to content

About

Monitoring algorithm for automatic shutoff of pool suction systems using a camera monitor

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Pool Safety Monitor & Telemetry Architecture

A robust, modular Python computer vision and hardware interlock system designed to monitor pool occupancy, track submersion duration in real-time, execute emergency interlocks on drain suction systems, and cross-reference short-term temporal assessments against a long-term JSON memory ledger to filter out environmental false positives (e.g., surface glare, water ripples, and shadows).

This probably can be a diy preventative measure to tack on to avoid a reoccurrence of the Rachel Fernando case.

Features

  • Real-Time Video Stream Processing: Built on OpenCV to capture live feeds from pool-facing cameras.
  • State-Machine Submersion Tracking: Precisely measures how long a subject has been underwater and triggers safety thresholds.
  • Hardware Interlock Integration: Automatically shuts down drain suction systems if a submersion event exceeds safe temporal limits.
  • Dual-Layer Telemetry Cross-Referencing: Dampens flickering and environmental artifacts by evaluating immediate frame confidence against rolling historical logs stored in persistent memory.
  • Persistent Audit Trail: Automatically logs session counts, historical durations, and anomaly flags to a local JSON database.

Prerequisites & Dependencies

Ensure you have Python 3.8+ installed along with OpenCV:

pip install opencv-python

Quick Start

  1. Save the monitoring script as pool_monitor.py.
  2. Configure your camera source (index 0 for default webcam, or an RTSP stream URL for an IP pool camera).
  3. Run the script:
from pool_monitor import PoolSafetyMonitor

if __name__ == "__main__":
    # Initialize monitor with a 12-second max submersion threshold
    monitor = PoolSafetyMonitor(camera_source=0, max_submersion_sec=12.0)
    monitor.run_monitor_loop()

Architecture & Customization

1. Vision Inference Pipeline

The analyze_frame(self, frame) method currently acts as a structural stub. For production deployments, replace this stub with a dedicated inference pipeline (such as a fine-tuned YOLOv8 model, MediaPipe Pose tracking, or custom segmentation) that evaluates bounding boxes relative to a defined water surface line.

2. Hardware Relays

The control_drain_suction(self, active: bool) method manages the safety interlock state. To connect this to physical hardware:

  • Raspberry Pi / Jetson Nano: Import RPi.GPIO and toggle a relay pin connected to your pool pump's contactor switch.
  • Smart Infrastructure: Replace print statements with an MQTT client publish or a webhook request to your home automation server (e.g., Home Assistant).

3. Long-Term Memory Ledger (pool_telemetry_memory.json)

The system maintains a local JSON state record to track historical performance and calibrate anomaly dampening over time:

{
    "session_count": 1,
    "false_positive_corrections": 0,
    "average_submersion_duration": 0.0,
    "historical_logs": [
        {
            "timestamp": "2026-10-14T16:30:00.000000",
            "duration": 4.2,
            "anomaly_flag": false
        }
    ]
}

About

Monitoring algorithm for automatic shutoff of pool suction systems using a camera monitor

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages