Flytrap: Real-Time Traffic Monitoring

Flytrap
Flytrap

Personal Project

2025

Vertical

AI/Machine Learning

Media Type(s)

Web Application
An Open-Source Python Project Delivering Real-Time Object Detection with SRT Video Streams

Overview

Flytrap is a sophisticated real-time object detection and tracking system that processes live video streams using computer vision technology. Built with YOLO11 (You Only Look Once version 11) and designed to handle SRT (Secure Reliable Transport) video streams, the project demonstrates advanced capabilities in tracking vehicles, people, and bicycles while calculating movement metrics such as direction and speed.

The project was initiated as a learning exercise to gain hands-on experience with computer vision and object detection technologies, evolving into a production-ready system with comprehensive monitoring and analytics capabilities.

References

System Pipeline

The processing pipeline follows a sophisticated four-stage workflow:

  1. Stream Reception: SRT video streams are received through the multi-method fallback system
  2. Frame Processing: Motion detection algorithms determine whether inference is necessary, skipping processing when no movement is detected to optimize performance
  3. Analytics Engine: Direction detection identifies left-to-right and right-to-left movement using midpoint crossing logic, while speed calculation estimates velocity in mph based on configurable road width parameters
  4. Data Storage: Comprehensive metrics are logged to files and stored in InfluxDB time-series database for historical analysis and real-time monitoring via Grafana dashboards

Key Features and Capabilities

Intelligent Processing

  • Motion-Based Inference: Reduces computational load by only processing frames when movement is detected
  • Region of Interest (ROI) Support: Allows focusing detection on specific areas, such as road surfaces, improving accuracy and performance
  • Built-in Object Tracking: Maintains consistent object tracking across frames

Analytics and Monitoring

  • Direction Detection: Calculates movement direction using spatial algorithms
  • Speed Estimation: Estimates object velocity in mph using configurable parameters
  • Time-Series Storage: Stores all metrics in InfluxDB for historical analysis
  • Real-Time Dashboards: Grafana integration for live monitoring and visualization
  • Event Logging: Generates annotated screenshots for detected events

Production Features

  • Multi-Platform Support: Runs on Linux, Windows (WSL2), and macOS
  • Hardware Acceleration: Automatic detection and utilization of CUDA, MPS, or CPU
  • Stream Resilience: Intelligent fallback between GStreamer, OpenCV, and FFmpeg
  • Headless Operation: Designed for server environments without display
  • Container Ready: Includes Docker configuration for easy deployment

Technical Architecture

The system is built on a modern technology stack that prioritizes performance, reliability, and scalability:

  • YOLO11 Object Detection: Leverages the latest iteration of the YOLO family, which offers 22% fewer parameters than YOLOv8 while achieving greater mean Average Precision (mAP) on benchmark datasets. YOLO11 introduces architectural innovations including the C3k2 block, SPPF (Spatial Pyramid Pooling Fast), and C2PSA (Cross-Stage Partial Attention) components for enhanced feature extraction.
  • SRT Streaming Protocol: Implements Secure Reliable Transport, an open-source protocol designed for ultra-low latency (sub-second) live video streaming. SRT combines UDP's speed with TCP's error-correction capabilities, delivering reliable streams over unpredictable networks while maintaining end-to-end AES encryption.
  • Multi-Method Stream Reception: Features intelligent fallback architecture with three streaming methods (GStreamer → OpenCV → FFmpeg) ensuring robust stream reception regardless of system configuration.
  • Hardware Acceleration: Supports multiple acceleration platforms including CUDA for NVIDIA GPUs, Apple Metal Performance Shaders (MPS) for Mac systems, and optimized CPU processing with automatic hardware detection.

Supported Platforms

  • Linux (native)
  • Windows (via WSL2)
  • macOS (with MPS acceleration support)

Hardware Requirements

  • NVIDIA GPU with CUDA support (optional, for acceleration)
  • Apple Silicon with Metal support (optional, for MPS acceleration)
  • Multi-core CPU for CPU-only processing

Problem

Real-time object detection and tracking from live video streams presents several interconnected technical challenges that must be addressed simultaneously for a production-ready system:

  1. Stream Reliability and Network Resilience
  2. Computational Efficiency vs. Detection Accuracy
  3. Cross-Platform Hardware Acceleration
  4. Long-Term Stability and Memory Management
  5. Analytics and Historical Insights
  6. Deployment Complexity
  7. Object Movement Analysis

To address these challenges, the system needed to:

  • Process live SRT video streams with sub-second latency and network resilience
  • Achieve real-time object detection (vehicles, people, bicycles) at 15+ fps
  • Automatically leverage CUDA, MPS, or CPU acceleration based on available hardware
  • Run continuously for days/weeks without memory degradation or crashes
  • Calculate object movement direction and estimate speeds in mph
  • Store detection metrics in queryable time-series database
  • Provide real-time monitoring dashboard for system health and detection statistics
  • Support headless deployment for server environments
  • Handle stream interruptions gracefully with automatic reconnection
  • Generate annotated screenshots for detected events
  • Minimize false positives through configurable region-of-interest filtering

Learning Outcomes

The project successfully achieved its educational objectives while delivering a production-ready system:

Computer Vision Expertise

  • Hands-on experience with state-of-the-art object detection algorithms (YOLO11)
  • Understanding of tracking algorithms and motion detection techniques
  • Implementation of region-based processing and spatial analytics

System Architecture Skills

  • Design of robust, fault-tolerant streaming pipelines with intelligent fallback mechanisms
  • Hardware acceleration optimization across multiple platforms (CUDA, MPS, CPU)
  • Memory management and resource optimization for long-running processes

DevOps and Monitoring

  • Integration of time-series databases for metrics storage
  • Real-time dashboard development with Grafana
  • Headless server deployment and environment detection

Video Streaming Technology

  • Implementation of modern streaming protocols (SRT)
  • Multi-codec support and stream processing optimization
  • Network resilience and error recovery strategies

Flytrap implements a modular, fault-tolerant architecture that addresses each challenge through specialized subsystems working in concert:

  1. Resilient Streaming Infrastructure with Intelligent Fallback
  2. Motion-Aware Inference Optimization
  3. Hardware-Adaptive Acceleration Layer
  4. Aggressive Memory Management System
  5. Time-Series Analytics Stack
  6. Containerized Deployment with Auto-Configuration
  7. Spatial Analytics Engine

The project transforms the initial learning objective—gaining experience with computer vision—into a production-grade system demonstrating mastery of modern ML operations, streaming infrastructure, and observability practices.