Skip to content

RchtDshr/video-streaming-object-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Live Object Detection

Real-time object detection system with mobile camera streaming and live browser visualization.

πŸš€ Quick Start

Prerequisites

  • Docker & Docker Compose
  • ngrok auth token (for public mobile access) - get from ngrok.com

Setup

  1. Set ngrok token (required for mobile access):
export NGROK_AUTHTOKEN=your_token_here
  1. Start all services:
docker-compose up --build

That's it! All services (backend, frontend, ngrok) will start automatically.

πŸ“± Mobile Connection

Option 1: QR Code (Recommended)

  1. Open browser at http://localhost:5173
  2. Scan QR code with phone camera
  3. Allow camera permissions when prompted

Option 2: Manual URL

  • Local Network: http://[your-ip]:5173
  • Public Access: Check http://localhost:4040 for ngrok URL

πŸŽ›οΈ Application URLs

After starting with docker-compose up:

  • Frontend: http://localhost:5173
  • Backend API: http://localhost:8000
  • ngrok Dashboard: http://localhost:4040 (shows public URL)
  • Health Check: http://localhost:8000/health

πŸ“Š Performance Monitoring

Monitor your application's performance using existing functionality:

# Start the application first
export NGROK_AUTHTOKEN=your_token_here
docker-compose up --build

Option 1: Run from Docker Container (Recommended)

# Enter the frontend container
docker exec -it frontend bash

# Run metrics collection
npm run bench

# View results
npm run metrics

Option 2: Run from Host Machine

# In a new terminal (application running)
cd frontend
npm install  # if not already done
npm run bench
npm run metrics

The metrics collector will automatically detect whether it's running inside Docker and use the appropriate URLs (backend:8000 vs localhost:8000).

Custom Duration

# 60-second monitoring
npm run bench 60

# 120-second monitoring  
npm run bench 120

The metrics collector will:

  • βœ… Monitor your existing application endpoints
  • βœ… Collect streaming statistics from /stream/stats
  • βœ… Check service health and connectivity
  • βœ… Generate realistic performance estimates
  • βœ… Produce metrics.json with benchmarking data

For Real Metrics

To get actual performance data:

  1. Start streaming from a mobile device
  2. Open the frontend at http://localhost:5173
  3. Use your phone to stream video while metrics are collected

Metrics Output

The system generates metrics.json containing:

  • Latency: Estimated end-to-end response times
  • Throughput: Target vs actual FPS based on streaming activity
  • Bandwidth: Projected bandwidth usage for video streaming
  • Connection: Service health and uptime monitoring
  • Analysis: Performance assessment and recommendations

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    WebSocket    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    HTTP/WS    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Mobile    │────────────────▢│   Backend   │──────────────▢│   Browser   β”‚
β”‚   Camera    β”‚                 β”‚  (Python)   β”‚               β”‚  (React)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚
                                  β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”
                                  β”‚ Object  β”‚
                                  β”‚Detectionβ”‚
                                  β”‚ (YOLO)  β”‚
                                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”§ Development

Docker Setup (Recommended)

# Set environment variable
export NGROK_AUTHTOKEN=your_token_here

# Build and start all services
docker-compose up --build

# Stop services
docker-compose down

Manual Development Setup

# Backend
cd backend
pip install -r requirements.txt
uvicorn app.main:app --reload

# Frontend (in another terminal)
cd frontend
npm install
npm run dev

# ngrok (in another terminal, optional)
ngrok http 5173

πŸ“ˆ Performance Optimizations

Low-Resource Mode

  • Input resolution: 320Γ—240 (configurable)
  • Target FPS: 10-15
  • Frame queue with overflow protection
  • Dynamic quality adjustment

Backpressure Handling

  • Fixed-length frame queue (default: 5 frames)
  • Drop oldest frames when overloaded
  • WebSocket flow control
  • Adaptive frame rate based on processing speed

πŸ›‘ Stopping

docker-compose down

# To remove volumes and networks
docker-compose down -v

πŸ“ Project Structure

β”œβ”€β”€ docker-compose.yml       # Docker orchestration
β”œβ”€β”€ ngrok.yml                # ngrok configuration  
β”œβ”€β”€ config.env              # Environment configuration
β”œβ”€β”€ backend/                 # Python FastAPI server
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── app/
β”‚       β”œβ”€β”€ main.py         # FastAPI app
β”‚       β”œβ”€β”€ websocket_service.py
β”‚       β”œβ”€β”€ connection_service.py
β”‚       └── api_service.py
β”œβ”€β”€ frontend/               # React web app
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ scripts/
β”‚   β”‚   β”œβ”€β”€ benchmark.js    # Performance testing
β”‚   β”‚   └── view-metrics.js # Metrics viewer
β”‚   └── src/
β”‚       β”œβ”€β”€ App.jsx
β”‚       β”œβ”€β”€ pages/
β”‚       └── utils/
└── metrics.json           # Benchmark results

🎯 Key Features

  • βœ… Real-time mobile camera streaming
  • βœ… QR code mobile connection
  • βœ… Performance metrics and benchmarking
  • βœ… Docker containerization
  • βœ… Responsive web interface

πŸ“‹ Design Report

Architecture Decisions

1. WebSocket Communication

  • Chosen for low-latency bi-directional communication
  • Enables real-time frame streaming and results delivery
  • Built-in backpressure handling through connection management

2. FastAPI Backend

  • Async request handling for better concurrency
  • Native WebSocket support
  • Easy integration with Python ML libraries

3. React Frontend

  • Component-based architecture for maintainable UI
  • Real-time canvas rendering for smooth overlay display
  • Service worker support for WASM mode

Low-Resource Implementation

Resolution Scaling:

  • Default: 320Γ—240 input resolution
  • Automatic upscaling for display
  • Configurable via environment variables

Processing Rate Control:

  • Target: 10-15 FPS processing
  • Skip frames during high load
  • Dynamic quality adjustment

Backpressure Policy

1. Frame Queue Management

  • Fixed-size circular buffer (5 frames default)
  • Automatic oldest-frame dropping
  • No blocking on queue full

2. WebSocket Flow Control

  • Connection state monitoring
  • Pause processing on slow consumers
  • Graceful degradation under load

3. Adaptive Quality

  • Lower resolution under high load
  • Reduced detection confidence thresholds
  • Frame skipping based on processing lag

4. Resource Monitoring

  • CPU/memory usage tracking
  • Automatic mode switching if needed
  • Client capability detection

Performance Targets

  • Latency: <200ms end-to-end (median), <500ms (P95)
  • Throughput: 10-15 FPS processed, 20-30 FPS display
  • Bandwidth: <1Mbps uplink, <500kbps downlink
  • Resource: <2GB RAM, <50% CPU single core

Future Improvements

  1. Hardware Acceleration: GPU support for inference
  2. Edge Optimization: TensorFlow Lite/ONNX for mobile
  3. Scalability: Redis for multi-instance deployment
  4. Analytics: Real-time performance dashboards

Built with ❀️ for real-time computer vision applications

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published