Skip to content

Real-time object detection and tracking system with YOLO11 and BoT-SORT

License

Notifications You must be signed in to change notification settings

bcpmarvel/sentinel

Repository files navigation

🎯 Sentinel

Real-time object detection and tracking system

CI Python 3.12+ License: MIT Code style: ruff

YOLO11 Γ— BoT-SORT Γ— FastAPI

Demo β€’ Quick Start β€’ Features β€’ Usage β€’ Docker


🎬 Demo

πŸ“Έ Object Detection

Pedestrian Detection
YOLO11 pedestrian detection
Traffic Detection
YOLO11 traffic detection

πŸŽ₯ Multi-Object Tracking

BoT-SORT multi-object tracking demo
Real-time tracking of 20+ pedestrians with trajectory prediction

πŸ“₯ Download Full Quality Video (34MB MP4)

πŸš€ Quick Start

Try it in 3 commands:

git clone https://github.com/bcpmarvel/sentinel.git
cd sentinel
uv run detect image demos/inputs/images/pedestrian.jpg

Models download automatically on first run. Output saved to demos/outputs/.

Prerequisites

  • Python 3.12+
  • uv package manager (install)

Installation

git clone https://github.com/bcpmarvel/sentinel.git
cd sentinel
uv sync

Try It Out

Detect objects in demo images:

# Pedestrian detection
uv run detect image demos/inputs/images/pedestrian.jpg

# Traffic detection
uv run detect image demos/inputs/images/traffic.jpg

Run on webcam:

uv run detect video --source 0

Track objects in video:

uv run detect video --source demos/inputs/videos/mot17-05.mp4 --track

Start API server:

uv run serve

Test the API:

curl -X POST http://localhost:8000/api/detect \
  -F "file=@demos/inputs/images/pedestrian.jpg"

✨ Features

Feature Description Status
🎯 YOLO11 Detection State-of-the-art object detection at 30+ FPS βœ…
πŸ”„ BoT-SORT Tracking Multi-object tracking with trajectory prediction βœ…
πŸ“Š Zone Analytics Count objects, measure dwell time, detect entries/exits βœ…
πŸš€ REST API Production-ready FastAPI server βœ…
πŸ”Œ WebSocket Streaming Real-time video streaming βœ…
⚑ GPU Acceleration MPS (Apple Silicon) and CUDA support βœ…
🐳 Docker Ready Containerized deployment with docker-compose βœ…

🐳 Docker Deployment

# Development (hot reload)
docker-compose up api

# Production
docker-compose --profile production up api-prod

πŸ› οΈ Usage

CLI Commands

Image Detection:

uv run detect image <image_path> [--conf 0.5] [--model yolo11m.pt]

Video Detection:

# Basic detection
uv run detect video --source 0                           # Webcam
uv run detect video --source video.mp4                   # Video file
uv run detect video --source rtsp://camera.ip            # RTSP stream

# With tracking
uv run detect video --source video.mp4 --track

# Advanced options
uv run detect video --source 0 \
  --model yolo11s.pt \
  --conf 0.6 \
  --track \
  --analytics \
  --zones zones.json

Available Models:

  • yolo11n.pt - Nano (fastest)
  • yolo11s.pt - Small
  • yolo11m.pt - Medium (default, balanced)
  • yolo11l.pt - Large
  • yolo11x.pt - Extra large (most accurate)
Advanced CLI Options
uv run detect video --help

Common options:

  • --conf: Confidence threshold (0-1, default: 0.25)
  • --device: Device (cpu/mps/cuda, auto-detected)
  • --model: YOLO model path
  • --track: Enable object tracking
  • --analytics: Enable zone analytics
  • --zones: Path to zones.json file
  • --no-display: Run without GUI window
  • --save-video: Save output video

API Endpoints

Start the server:

uv run serve

Health Check:

curl http://localhost:8000/api/health

Detect Objects:

curl -X POST http://localhost:8000/api/detect \
  -F "file=@demos/inputs/images/pedestrian.jpg" \
  -F "conf_threshold=0.5"

Response:

{
  "detections": [
    {
      "x1": 123.4, "y1": 456.7,
      "x2": 789.0, "y2": 321.5,
      "confidence": 0.89,
      "class_id": 0,
      "class_name": "person"
    }
  ],
  "image_width": 1280,
  "image_height": 720,
  "processing_time_ms": 45.2,
  "model_name": "yolo11m.pt",
  "device": "mps"
}

Interactive API Docs:

More API Examples

With custom confidence threshold:

curl -X POST http://localhost:8000/api/detect \
  -F "file=@myimage.jpg" \
  -F "conf_threshold=0.7"

Using Python requests:

import requests

with open("image.jpg", "rb") as f:
    response = requests.post(
        "http://localhost:8000/api/detect",
        files={"file": f},
        data={"conf_threshold": 0.5}
    )

print(response.json())
Zone Analytics

Create zones.json to define monitoring zones:

[
  {
    "id": "zone_1",
    "name": "Entrance",
    "polygon": [[100, 100], [500, 100], [500, 400], [100, 400]],
    "color": [255, 0, 0]
  }
]

Metrics tracked:

  • Object count in zone
  • Average/max dwell time
  • Entry/exit events

βš™οΈ Configuration

Docker/API Deployment

Use .env for environment variables:

cp .env.example .env
MODEL_NAME=yolo11m.pt
DEVICE=cpu
API_HOST=0.0.0.0
API_PORT=8000
LOG_FORMAT=json

CLI Configuration

Configuration is managed through:

  • Command-line options for per-run settings
  • Environment variables (via .env) for persistent settings

See Docker/API Deployment section above for .env configuration.


πŸ—οΈ Architecture

Note: Architecture diagram placeholder

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Input     │─────▢│   YOLO11     │─────▢│  BoT-SORT   β”‚
β”‚ (Video/API) β”‚      β”‚  Detection   β”‚      β”‚  Tracking   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                   β”‚
                                                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Output    │◀─────│ Visualization│◀─────│  Analytics  β”‚
β”‚ (API/Stream)β”‚      β”‚  & Rendering β”‚      β”‚   (Zones)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Project Structure
src/sentinel/
β”œβ”€β”€ api/              # FastAPI routes, schemas, dependencies
β”‚   β”œβ”€β”€ app.py
β”‚   β”œβ”€β”€ routes.py
β”‚   β”œβ”€β”€ schemas.py
β”‚   └── dependencies.py
β”œβ”€β”€ analytics/        # Zone analytics, dwell time tracking
β”‚   β”œβ”€β”€ service.py
β”‚   β”œβ”€β”€ models.py
β”‚   └── dwell.py
β”œβ”€β”€ detection/        # YOLO11 detector, service
β”‚   β”œβ”€β”€ service.py
β”‚   └── models.py
β”œβ”€β”€ visualization/    # Annotators for drawing
β”‚   └── annotators.py
β”œβ”€β”€ cli.py            # CLI entrypoint
β”œβ”€β”€ server.py         # API server entrypoint
β”œβ”€β”€ config.py         # Pydantic settings
└── pipeline.py       # Video processing pipeline

🧰 Tech Stack

Component Technology
Detection YOLO11 (Ultralytics)
Tracking BoT-SORT
Deep Learning PyTorch (MPS/CUDA)
API Framework FastAPI
Computer Vision OpenCV, Supervision
CLI Typer
Logging Structlog
Packaging uv

πŸ§ͺ Development

Setup

uv sync --dev

Code Quality

# Format
uv run ruff format .

# Lint
uv run ruff check .

# Fix
uv run ruff check --fix .

Testing

uv run pytest
uv run pytest -v --cov=sentinel

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments