Skip to main content
Open In Colab

The Story

The stunning Arizona deserts, known for their dry riverbeds and scenic beauty, hide a deadly risk. During the summer monsoon, sudden torrential rains can trigger flash floods in these seemingly harmless dry zones — with little or no warning. Conventional alert systems relying on rain gauges or weather satellites often fail to deliver timely, location-specific warnings. By the time a danger alert is sent, it might already be too late. But we have a smarter way. With VideoDB RTStream, we can install real-time cameras near flood-prone areas and let AI continuously monitor the visuals. As soon as the AI detects signs of a flash flood — like a sudden surge of water through dry land — it can instantly send alerts, giving local authorities and tourists precious moments to act.

What You’ll Build

With VideoDB RTStream, you can build a two-layer monitoring system that:
  • Continuously monitors dry riverbeds and surrounding areas
  • Detects flash floods immediately upon occurrence
  • Identifies heavy rainfall as early warning signals
  • Alerts for people in distress requiring rescue
  • Sends real-time notifications to emergency services

Setup

Install Dependencies

pip install videodb

Connect to VideoDB

import videodb

api_key = "your_api_key"
conn = videodb.connect(api_key=api_key)
coll = conn.get_collection()

Implementation

Step 1: Connect to the Flood Monitoring Stream

rtsp_url = "rtsp://samples.rts.videodb.io:8554/floods"
flood_stream = coll.connect_rtstream(
    name="Flood Detection Stream",
    url=rtsp_url,
)

Step 2: Create Primary Index - Flash Flood Detection

Create the primary scene index focused on immediate flood detection with more frequent analysis:
flood_scene_index = flood_stream.index_visuals(
    batch_config={
        "type": "time",
        "value": 5,
        "frame_count": 3,
    },
    prompt="""Monitor the dry riverbed and surrounding area. If moving water is detected
              across the land, identify it as a flash flood and describe the scene.""",
    name="Flash_Flood_Detection_Index",
)
The frame_count: 3 captures 3 frames every 5 seconds for detailed water movement analysis.

Step 3: Create Secondary Index - Early Warning System

Create a second index on the same stream for early warning detection:
early_warning_index = flood_stream.index_visuals(
    batch_config={
        "type": "time",
        "value": 15,
        "frame_count": 1,
    },
    prompt="""Monitor the dry riverbed and surrounding area. In case you detect heavy rainfall
              mention 'heavy rainfall detected'. If you detect a person stuck in the area during
              rainfall or flash flood mention 'person detected, rescue needed'""",
    name="Early_Warning_Index",
)
The longer interval (value: 15) and single frame are sufficient for general rainfall and rescue detection.

Step 4: Define Three Events

Create events for the three alert types:
# Flash Flood Event
flood_event_id = conn.create_event(
    event_prompt="Detect a flash flood - sudden water surge across the riverbed.",
    label="flash_flood",
)

# Heavy Rainfall Event (early warning)
rainfall_event_id = conn.create_event(
    event_prompt="Detect heavy rainfall - potential precursor to flooding.",
    label="heavy_rainfall",
)

# Rescue Needed Event
rescue_event_id = conn.create_event(
    event_prompt="Detect a person in distress or stuck - rescue needed.",
    label="person_rescue_needed",
)

Step 5: Attach Alerts

webhook_url = "https://your-webhook-url.com"

# Primary flood detection alerts
flood_alert_id = flood_scene_index.create_alert(flood_event_id, callback_url=webhook_url)

# Early warning alerts
rainfall_alert_id = early_warning_index.create_alert(rainfall_event_id, callback_url=webhook_url)
rescue_alert_id = early_warning_index.create_alert(rescue_event_id, callback_url=webhook_url)

Alert Payloads

Flash Flood Alert (Critical Priority)

When a flood is detected, the system sends an immediate alert with the exact location and video:
{
  "event_id": "event-flood-detection",
  "label": "flash_flood",
  "confidence": 0.95,
  "explanation": "Flash flood detected! Water is flowing rapidly and forcefully through the riverbed. The water appears muddy, carrying sediment and debris. Multiple people visible on rocky banks.",
  "timestamp": "2025-05-29T07:17:51.123456+00:00",
  "start_time": "2025-05-29T07:17:51.000000+05:30",
  "end_time": "2025-05-29T07:17:56.000000+05:30",
  "stream_url": "https://rt.stream.videodb.io/manifests/rts-019711a0-0fde-7911-b282-25bc0b4ecf65/1748475471000000-1748475476000000.m3u8"
}

Heavy Rainfall Alert (Warning Priority)

Early warning alerts help authorities respond proactively:
{
  "event_id": "event-rainfall-warning",
  "label": "heavy_rainfall",
  "confidence": 0.85,
  "explanation": "Heavy rainfall detected in the monitoring area. Conditions favorable for flash flooding.",
  "timestamp": "2025-05-29T07:10:00.000000+00:00",
  "start_time": "2025-05-29T07:10:00.000000+05:30",
  "end_time": "2025-05-29T07:10:15.000000+05:30",
  "stream_url": "https://rt.stream.videodb.io/manifests/rts-019711a0-0fde-7911-b282-25bc0b4ecf65/1748475000000000-1748475015000000.m3u8"
}

The Result

With this system in place, communities, tourists, and local authorities in Arizona’s desert regions can receive immediate alerts when a dangerous flash flood occurs — gaining critical seconds to take cover, clear routes, or initiate rescues. The two-layer system ensures:
  • Real-time flood detection for immediate response
  • Early rainfall warnings for proactive preparation
  • Rescue alerts for people in distress

Explore the Full Notebook

Open the complete implementation with advanced monitoring features and configuration options.