Skip to main content

Overview

Single stream mode processes one RTSP camera feed with real-time person detection. When a person enters the frame, the system can:
  • Save an annotated JPEG snapshot
  • Record an MP4 video clip of their presence
  • Display a live annotated window
  • Print detection events to console
Single stream mode uses a dedicated display window (1280×720 resolution). For multiple cameras, see Multi-Stream Processing.

Basic Usage

Minimal Example

This command:
  • Connects to the RTSP stream
  • Runs person detection on every 15th frame (default)
  • Saves JPEG snapshots when persons are detected
  • Shows a live display window

Command Structure

The basic command structure for single stream processing:
string
required
RTSP stream URL to process
choice
required
Save mode: image for snapshots or video for clips

Display Options

Control whether to show a live display window during processing.

With Display (Default)

By default, single stream mode shows a live annotated window:
Window features:
  • Resized to 1280×720 for consistent viewing
  • Green bounding boxes around detected persons
  • Confidence scores displayed above boxes
  • Person count and entry counter in top-left
  • Press ‘q’ to quit
Implementation (stream_processor.py:363-396):

Without Display (Headless)

Disable the display window for headless servers or background processing:
flag
Disable the live display window (single stream only)
Use cases:
  • Running on servers without GUI
  • Background processing
  • Reduced resource usage
  • Remote/SSH sessions
From main.py:142:
Output:
  • Live OpenCV window appears

Save Modes

Image Mode (Snapshots)

Captures a single annotated JPEG when a person first enters the frame.
Behavior:
  • One snapshot per person entry event
  • Annotated with bounding boxes and confidence scores
  • Saved immediately when person detected
  • Filename includes timestamp and entry counter
Filename format:
Example output:
Implementation (stream_processor.py:321-327):
Annotation function (stream_processor.py:416-434):
When to use image mode:
  • Counting people entering an area
  • Logging distinct events
  • Minimal storage requirements
  • Quick review of detections

Video Mode (Clips)

Records an MP4 clip for the entire duration a person is present in the frame.
Behavior:
  • Recording starts when person enters frame
  • Continues while person is present
  • Stops after 3 consecutive frames without detection
  • All frames written at source stream FPS
Filename format:
Example output:
Implementation (stream_processor.py:329-339):
Exit detection logic (stream_processor.py:344-355):
Exit threshold: 3 consecutive frames without detectionWith frame_skip=15 on a 30fps stream:
  • Detection runs every 0.5 seconds
  • 3 misses = ~1.5 seconds of no detection
  • Prevents premature clip termination from brief occlusions
When to use video mode:
  • Reviewing behavior and movement
  • Security incident investigation
  • Understanding context around events
  • Capturing full interactions

Save Mode Comparison

Image Mode

Pros:
  • Minimal storage
  • Fast to review
  • One file per event
  • Good for counting
Cons:
  • No temporal context
  • Miss behavior details
  • Single frame only

Video Mode

Pros:
  • Full context
  • Review behavior
  • Continuous recording
  • Better for security
Cons:
  • Large file sizes
  • More storage needed
  • Slower to review

Detection Flow

Understanding how detection works in single stream mode:
1

Connect to RTSP stream

From stream_processor.py:251-254
2

Read frames continuously

From stream_processor.py:280-296
3

Run detection every Nth frame

From stream_processor.py:303-305
  • Default: every 15th frame
  • Throttled to max 2 fps
4

Track person presence state

From stream_processor.py:311-355
5

Save or display frames

  • Write frames to video clip if recording
  • Update display window if enabled
  • Print status messages

Console Output

Understanding the console output during processing:
Key indicators:
Confirms which detection model is active and compute backend.
Stream connection established and frame reading started.
Person detected with timestamp and entry counter.
Exit confirmation after 3 consecutive frames without detection.

Configuration Overrides

Override config.cfg values for single stream processing:

Automatic Reconnection

Single stream mode includes automatic reconnection on connection loss:
From stream_processor.py:282-296 Reconnection behavior:
  • Max 5 retry attempts
  • 2 second delay between attempts
  • Resets counter on successful read
  • Exits after exhausting retries
Video clips in progress when connection is lost will be saved automatically but may be incomplete.

Real-World Examples

Example 1: Store Entrance Monitoring

Goal: Count customers entering a store
Configuration:
  • Image mode: one snapshot per customer
  • Higher confidence: reduce false positives
  • Larger area threshold: only detect close persons (actually entering)
  • No display: runs in background

Example 2: Security Incident Recording

Goal: Record full video of any activity in restricted area
Configuration:
  • Video mode: capture full behavior
  • Lower confidence: don’t miss any detections
  • More frequent checking: faster detection response
  • With display: monitor in real-time

Example 3: Parking Lot Wide-Angle

Goal: Detect people in large parking area
Configuration:
  • Image mode: event logging
  • Lower confidence: better for distant detection
  • Low area threshold: detect small/distant persons
  • Less frequent: acceptable for slow-moving subjects

Troubleshooting

Error:
Possible causes:
  • Incorrect RTSP URL
  • Network connectivity issues
  • Camera authentication required
  • Firewall blocking connection
Solutions:
  • Verify URL with VLC or ffplay:
  • Check network connectivity:
  • Add credentials to URL:
Issue: No OpenCV window appearsPossible causes:
  • --no-display flag set
  • Headless environment (no X server)
  • Display environment variable not set
Solutions:
  • Remove --no-display flag
  • For SSH: enable X11 forwarding
  • Set DISPLAY variable:
Issue: Stream works but no persons detectedDebugging steps:
  1. Check model is loaded:
  2. Lower confidence threshold:
  3. Lower area threshold:
  4. Test with image first:
Issue:
Possible causes:
  • Unstable network
  • Camera stream issues
  • Network bandwidth limitations
  • Router/switch problems
Solutions:
  • Check network stability
  • Reduce stream quality at camera
  • Use wired connection instead of WiFi
  • Check camera logs for issues
Issue: System resources maxed outSolutions:
  1. Increase frame_skip:
  2. Disable display:
  3. Use HOG instead of YOLO:
    • Move YOLO weights out of model directory
    • HOG is faster but less accurate
  4. Enable GPU if available:

Performance Tips

Optimize frame_skip

Start with frame_skip=30 and decrease until detection responsiveness is acceptable.

Use GPU acceleration

CUDA-enabled OpenCV provides 5-10x speedup. See GPU setup.

Adjust resolution

Configure camera to stream at lower resolution (e.g., 1280×720 instead of 1920×1080).

Tune thresholds

Higher confidence/area thresholds = fewer detections = less processing.

Next Steps

Multi-Stream Processing

Monitor multiple cameras simultaneously

Configuration

Fine-tune detection parameters

GPU Acceleration

Speed up detection with CUDA

Model Setup

Configure detection models