VisionGrid is an advanced, production-ready computer vision platform for high-throughput multi-object detection, state-space kinematic tracking, and real-time spatial analytics. Combining Ultralytics YOLOv8 deep convolutional neural networks with the mathematical rigour of SORT (Simple Online and Realtime Tracking) Kalman filters and the Hungarian algorithm, VisionGrid delivers millisecond-latency telemetry, bidirectional virtual tripwire analytics, dynamic class filtering, and an interactive Cyber Command Center.
- System Architecture
- Key Capabilities & Highlights
- Dual Execution Modes
- Project Structure & File Breakdown
- Installation & Environment Setup
- Quickstart & Usage Guide
- CLI Command Reference
- Algorithmic & Mathematical Foundations
- Benchmark Datasets & Performance
- Troubleshooting & FAQs
- Submission Details & Acknowledgements
VisionGrid is designed as a modular, decoupled computer vision pipeline supporting real-time video ingestion, deep neural inference, kinematic trajectory estimation, and multi-channel telemetry dispatching:
| Pipeline Layer | Description | Architectural Core |
|---|---|---|
| 📹 1. Ingestion Layer | Ingests frames from live webcams, user-uploaded video files (.mp4, .webm, .avi), or built-in benchmark clips (Sample 1 & Sample 2). |
OpenCV cv2.VideoCapture + getUserMedia API |
| 🧠 2. Neural Detection & Refinement | Executes deep CNN forward-pass across 80 COCO classes, applying specialized color-moment animal refinement and fast IoU Non-Maximum Suppression (NMS). | Ultralytics YOLOv8 Nano (yolov8n.pt) + PyTorch |
| 🔄 3. Kinematics & SORT Tracking | Estimates 7D continuous state trajectories |
7-State Kalman Filter + Hungarian Algorithm |
| 🚧 4. Spatial Analytics & Tripwire | Computes directional crossings (IN / OUT), instantaneous target velocity vectors ( |
Vector Crossing Logic + Kinematic Velocity Engine |
| 🌐 5. Presentation & Telemetry Dispatch | Serves the interactive Cyber Web Command Center over WebSockets with timeline scrubbing, while supporting headless OpenCV desktop execution. | FastAPI + WebSockets + HTML5 Canvas & OpenCV HUD |
| Feature | Description | Architectural Core |
|---|---|---|
| 🚀 Deep Neural Object Detector | High-throughput object detection across 80 Microsoft COCO classes with bounding box localization and confidence scoring. | Ultralytics YOLOv8 CNN + PyTorch CUDA/CPU |
| 🎯 Feline / Canine Visual Discriminator | Post-processing visual refiner resolving fine-grained quadruped ambiguities using HSV chromaticity moments and aspect-ratio kinematics. | Color-Moment Analyzer (core/detector.py) |
| ⚡ Fast IoU NMS Deduplication | Dynamic post-inference spatial suppression eliminating ghost bounding boxes and duplicate detections in dense frames. | Greedy IoU Non-Maximum Suppression |
| 🔄 7-State Kalman Filter Tracking | Continuous state-space motion filtering modeling centroid |
Linear Dynamical Kalman Filter (tracker/sort.py) |
| 🧩 Hungarian Data Association | Solves global multi-object tracking assignments as a minimum-cost bipartite matching problem across the IoU cost matrix. | SciPy Munkres Linear Assignment Algorithm |
| 🚧 Bidirectional Virtual Tripwire | Stateful counting tripwire evaluating centroid vector crossings IN / OUT). |
Spatial Boundary State Machine |
| 🌐 Cyber Web Command Center | Real-time FastAPI WebSocket dashboard featuring live KPI ribbons, interactive timeline scrubber, class filters, and Cyber Vault theme switcher. | FastAPI + WebSockets + TailwindCSS |
| 🖥️ Standalone OpenCV Desktop HUD | High-performance CLI engine with real-time HUD telemetry overlay, interactive hotkeys, video recording (--save), and CSV logging (--save-log). |
OpenCV cv2.imshow + Multi-Threaded VideoStream |
| 📊 Telemetry Export Suite | Instant client-side and server-side data extraction exporting timestamped audit trails in JSON, structured CSV, PNG snapshots, and WebM video. | Client-side Blob Serialization + CSV Logger |
VisionGrid offers two execution modes suited for different deployment environments:
Recommended for interactive monitoring, remote surveillance streaming, and visual data exploration.
- Backend: FastAPI asynchronous server with WebSocket streaming on port
8000. - Frontend: Lightweight vanilla JavaScript and CSS dashboard with responsive canvas overlays.
- Features: 1-click video presets (
Sample 1&Sample 2), drag-and-drop file upload, webcam ingestion, live activity logger, and theme switching.
Recommended for high-throughput batch processing, embedded edge devices (e.g. Raspberry Pi / Jetson), and CLI-driven headless pipelines.
- Backend: Pure Python + OpenCV
cv2.imshowhigh-FPS pipeline. - Features: Heads-Up Display (HUD), keyboard shortcuts, customizable class arguments, video export (
--save), and telemetry export (--save-log).
CodeAlpha_ObjectDetectionTracking/
│
├── core/
│ ├── __init__.py # Package initializer
│ ├── detector.py # YOLOv8 detector with animal refinement & Fast NMS
│ └── video_stream.py # Multi-source thread-safe video capture pipeline
│
├── tracker/
│ ├── __init__.py # Package initializer
│ ├── sort.py # Pure NumPy/SciPy Kalman Filter SORT tracker
│ └── deep_sort_tracker.py # ByteTrack / cascaded association tracker
│
├── sample_data/
│ ├── Sample1.mp4 # Benchmark clip 1 (Person, Vehicles, Animals)
│ └── Sample2.mp4 # Benchmark clip 2 (Person, Vehicles, Animals)
│
├── uploads/ # Working directory for uploaded user videos
│
├── web/
│ ├── index.html # VisionGrid Web Command Center interface
│ ├── app.js # Frontend controller & WebSocket client
│ ├── styles.css # Custom styling definitions & theme palettes
│ └── tracker_web.js # In-browser SORT tracking module
│
├── main.py # Standalone OpenCV desktop CLI application
├── server.py # FastAPI streaming & WebSocket server
├── yolov8n.pt # Pre-trained YOLOv8 Nano weights (6.4 MB)
├── requirements.txt # Python dependencies
└── README.md # System documentation
- Python: Version
3.10,3.11, or3.12installed. - Web Browser: Google Chrome, Microsoft Edge, Mozilla Firefox, or Brave.
- Camera (Optional): USB webcam or integrated laptop camera for live feeds.
cd D:\Projects\CodeAlpha_ObjectDetectionTracking# Windows (PowerShell)
python -m venv venv
.�env\Scripts\Activate.ps1
# Linux / macOS
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtStart the asynchronous FastAPI server:
python server.pyOnce running, navigate to http://localhost:8000 in your browser.
- Source Selection: Click Sample 1 or Sample 2 for built-in benchmark clips, Webcam for live camera feeds, or Upload to drop your own MP4/WebM video.
- Class Filtering: Click
Person,Vehicles, orAnimalsin the left sidebar to isolate specific object categories. - Threshold Tuning: Adjust the Confidence Slider (default:
0.40) and Track Max Age (default:30frames) in real-time. - Tripwire Position: Adjust the Tripwire Slider to move the virtual counting line vertically.
- Data Export: Click Export JSON or Export CSV in the header to download the full telemetry audit trail.
- Theme Switcher: Click the Vault Toggle in the top right to switch between DARK (Cyan) and LIGHT (Yellow).
Run on default webcam (index 0):
python main.py --source 0Run on the benchmark sample video:
python main.py --source sample_data/Sample1.mp4Filter specific object classes:
python main.py --source sample_data/Sample1.mp4 --classes person car dog catRecord and save processed video output to disk:
python main.py --source sample_data/Sample1.mp4 --save output_tracked.mp4Export tracking telemetry logs to CSV:
python main.py --source sample_data/Sample1.mp4 --save-log tracking_telemetry.csv| Parameter | Type | Default | Description |
|---|---|---|---|
--source |
str |
sample_data/Sample1.mp4 |
Video path (.mp4, .avi), RTSP stream URL, or webcam index (0, 1). |
--model |
str |
yolov8n.pt |
Path to YOLOv8 model weights file. |
--conf |
float |
0.40 |
Minimum object detection confidence threshold (0.05 to 0.95). |
--iou |
float |
0.45 |
Non-Maximum Suppression (NMS) IoU threshold. |
--classes |
list |
None |
Filter by specific class names (e.g. --classes person car bicycle). |
--max-age |
int |
30 |
Maximum frames to retain lost tracks before deletion. |
--min-hits |
int |
3 |
Minimum consecutive detections required to validate a track. |
--iou-thresh |
float |
0.30 |
SORT tracker IoU association threshold. |
--save |
str |
None |
Output file path to record tracked video with HUD overlay. |
--save-log |
str |
None |
Output file path (.csv or .json) to save full tracking logs. |
--no-display |
flag |
False |
Run in headless mode without opening GUI window. |
| Key | Action |
|---|---|
Q or ESC |
Exit application safely |
P |
Pause / Resume video playback |
S |
Capture high-resolution PNG snapshot to disk |
T |
Toggle motion trajectory trails |
L |
Toggle counting tripwire line |
H |
Toggle HUD metrics overlay |
R |
Reset tracker state and tripwire counts |
Each object track maintains a continuous linear dynamical system modeling position, scale, aspect ratio, and linear velocities:
Where:
-
$(u, v)$ : Center coordinates of the bounding box -
$s = w imes h$ : Total bounding box pixel area (scale) -
$r = rac{w}{h}$ : Bounding box aspect ratio (assumed constant under uniform motion) -
$(\dot{u}, \dot{v}, \dot{s})$ : First-order velocity derivatives
Where the state transition matrix
Given detection measurement
Data association between predicted Kalman track locations and detected bounding boxes is solved as an optimal bipartite matching problem minimizing total cost
The Munkres (Hungarian) algorithm solves this assignment in
The virtual tripwire counts targets crossing a horizontal boundary line
-
IN (Entering):
$(y_{ ext{prev}} < Y_{ ext{line}} \le y_{ ext{curr}})$ with$\Delta y > 0$ . -
OUT (Exiting):
$(y_{ ext{prev}} > Y_{ ext{line}} \ge y_{ ext{curr}})$ with$\Delta y < 0$ .
A stateful registry prevents duplicate counting for targets hovering near the boundary line.
To resolve COCO pre-trained dataset bias where cats in outdoor motion are misclassified as dogs:
- Color-Moment & Morphometrics: The visual refiner in
core/detector.pycrops animal bounding boxes, analyzes HSV chromaticity distributions (e.g. ginger/calico/black feline fur patterns vs. canine coats), calculates elongation ratios, and compares spatial bounding heights relative to human handlers. - Kinematic Smoothing: Temporal consensus prevents momentary single-frame label flickering.
| Dataset | Resolution | Framerate | Duration | Targets Tracked | Primary Classes Detected |
|---|---|---|---|---|---|
Sample1.mp4 |
1280×720 (HD) | 24 FPS | 8.0s | 12+ | person, car, truck, bicycle, dog, cat |
Sample2.mp4 |
1280×720 (HD) | 24 FPS | 10.0s | 10+ | person, car, bicycle, dog, cat |
| Hardware Device | Device Type | Average FPS | Inference Latency | Tracking Overhead |
|---|---|---|---|---|
| Intel Core i7-12700H | CPU | 38 - 45 FPS | ~22 ms | ~1.2 ms |
| AMD Ryzen 7 5800X | CPU | 40 - 48 FPS | ~20 ms | ~1.1 ms |
| NVIDIA RTX 3060 / 4060 | GPU (CUDA) | 110 - 145 FPS | ~6.5 ms | ~0.8 ms |
VisionGrid automatically detects CUDA availability. If an NVIDIA GPU with CUDA is present and torch with CUDA support is installed, YOLOv8 will execute on cuda:0 automatically. Otherwise, it seamlessly falls back to CPU.
Ensure your browser has permission to access the webcam (chrome://settings/content/camera). Also verify that no other application (e.g. Zoom or Teams) is locking the webcam hardware.
Yes! Simply pass the path to your custom weights:
python main.py --model path/to/best.pt --source your_video.mp4- Organization: CodeAlpha
- Program: Artificial Intelligence Internship
- Task: Task 4 — Real-Time Multi-Object Detection and Tracking
- Author: Arpan
- Technologies Used: Python 3, Ultralytics YOLOv8, OpenCV, NumPy, SciPy, FastAPI, WebSockets, HTML5, CSS3, JavaScript.
This project is licensed under the MIT License — see the LICENSE file for details.