Real-time object detection system with mobile camera streaming and live browser visualization.
- Docker & Docker Compose
- ngrok auth token (for public mobile access) - get from ngrok.com
- Set ngrok token (required for mobile access):
export NGROK_AUTHTOKEN=your_token_here
- Start all services:
docker-compose up --build
That's it! All services (backend, frontend, ngrok) will start automatically.
- Open browser at
http://localhost:5173
- Scan QR code with phone camera
- Allow camera permissions when prompted
- Local Network:
http://[your-ip]:5173
- Public Access: Check
http://localhost:4040
for ngrok URL
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
Monitor your application's performance using existing functionality:
# Start the application first
export NGROK_AUTHTOKEN=your_token_here
docker-compose up --build
# Enter the frontend container
docker exec -it frontend bash
# Run metrics collection
npm run bench
# View results
npm run metrics
# 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
).
# 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
To get actual performance data:
- Start streaming from a mobile device
- Open the frontend at
http://localhost:5173
- Use your phone to stream video while metrics are collected
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
βββββββββββββββ WebSocket βββββββββββββββ HTTP/WS βββββββββββββββ
β Mobile ββββββββββββββββββΆβ Backend ββββββββββββββββΆβ Browser β
β Camera β β (Python) β β (React) β
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β
ββββββΌβββββ
β Object β
βDetectionβ
β (YOLO) β
βββββββββββ
# Set environment variable
export NGROK_AUTHTOKEN=your_token_here
# Build and start all services
docker-compose up --build
# Stop services
docker-compose down
# 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
- Input resolution: 320Γ240 (configurable)
- Target FPS: 10-15
- Frame queue with overflow protection
- Dynamic quality adjustment
- Fixed-length frame queue (default: 5 frames)
- Drop oldest frames when overloaded
- WebSocket flow control
- Adaptive frame rate based on processing speed
docker-compose down
# To remove volumes and networks
docker-compose down -v
βββ 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
- β Real-time mobile camera streaming
- β QR code mobile connection
- β Performance metrics and benchmarking
- β Docker containerization
- β Responsive web interface
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
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
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
- 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
- Hardware Acceleration: GPU support for inference
- Edge Optimization: TensorFlow Lite/ONNX for mobile
- Scalability: Redis for multi-instance deployment
- Analytics: Real-time performance dashboards
Built with β€οΈ for real-time computer vision applications