Object Recognition Platform — Upload images or videos, or use your webcam. YOLOv8 detects objects in real time with bounding boxes, confidence scores, and batch processing.
Full-stack: FastAPI backend + vanilla JS frontend + YOLOv8 inference.
| Feature | Description |
|---|---|
| 📸 Batch Image Analysis | Upload single or multiple images (up to 500+). Each image is processed with bounding boxes drawn directly on the preview. |
| 🎬 Video Analysis | Upload MP4, AVI, MOV, MKV, or WebM. Video is sampled at 1 FPS, each frame is analyzed with bounding boxes overlaid. Interactive timeline for quick navigation. |
| 📹 Live Webcam | Start your camera and see detections update every second. Bounding boxes are drawn live over the video feed. |
| 📊 Class Distribution Chart | Collapsible bar chart showing detected class frequency with gradient bars (red → yellow → green). |
| 🎚️ Confidence Filter | Slider to dynamically hide/show detections below a confidence threshold. |
| 📥 Export | Download results as CSV or download individual annotated images with bounding boxes. |
| 📋 Session History | Past detection sessions are saved in your browser (localStorage). Browse and revisit them anytime. |
| 🌙☀️ Theme Toggle | Switch between dark and light themes. Preference is persisted across sessions. |
| ⌨️ Keyboard Shortcuts | Space (webcam), E (export), R (clear), 1-5 (tab navigation). |
| 🎯 Sidebar Navigation | Tab-based layout with isolated sections for Images, Video, Webcam, History, and About. |
| Layer | Tech |
|---|---|
| Object Detection | YOLOv8 (Ultralytics) |
| Backend | FastAPI + Python 3.12+ |
| Frontend | Vanilla HTML/CSS/JS (no framework) — canvas-based rendering with bounding boxes |
| Image/Video Processing | OpenCV, NumPy |
| Deployment | Docker |
git clone https://github.com/L2santos29/cortex-vision.git
cd cortex-vision
make runThe Makefile automatically creates a virtual environment and installs dependencies. Open http://localhost:8000.
# Clone
git clone https://github.com/L2santos29/cortex-vision.git
cd cortex-vision
# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install PyTorch (CPU-only, no CUDA required)
pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
# Install remaining dependencies
pip install -r requirements.txt
# Run
python -m src.maindocker build -t cortex-vision .
docker run -p 8000:8000 cortex-visioncortex-vision/
├── src/
│ ├── main.py # FastAPI app — routes, middleware setup
│ ├── config.py # Pydantic settings from env vars
│ ├── detector.py # YOLOv8 inference engine (detect + detect_array)
│ ├── pipeline.py # Batch processing and aggregation
│ ├── services.py # Service layer — upload, validation, detection orchestration
│ ├── cache.py # LRU detection cache to avoid redundant inference
│ ├── resilience.py # Circuit breaker + retry with exponential backoff
│ ├── middleware.py # Auth, CORS, rate limiting, security headers, metrics, tracing
│ ├── profiling.py # Performance decorators (@timed) and context managers
│ ├── utils.py # Validation, magic-byte checks, frame extraction, drawing
│ └── cli.py # Command-line interface (detect, serve subcommands)
├── static/
│ └── index.html # Full web UI — tabs, canvas, webcam, history
├── tests/
│ ├── smoke/ # Module imports, app instantiation
│ ├── unit/ # Unit tests for services, routes, profiling, utils
│ ├── edge/ # Edge cases — nulls, boundaries, malformed inputs
│ ├── integration/ # API + middleware integration tests
│ ├── contract/ # API response schema and status code checks
│ ├── property/ # Hypothesis property-based tests
│ ├── regression/ # Regression tests for known bugs
│ ├── performance/ # pytest-benchmark baselines
│ └── fault/ # Fault injection — disk full, network timeout, bad auth
├── deploy/
│ ├── docker-compose.staging.yml # Staging environment with Caddy + TLS
│ ├── Caddyfile # Reverse proxy config with Let's Encrypt
│ ├── prometheus-alerts.yml # Alerting rules for production
│ └── grafana-dashboard.json # Grafana dashboard definition
├── .github/
│ ├── workflows/ci.yml # CI — tests + coverage + lint + dependency audit
│ ├── workflows/deploy-staging.yml # Staging deployment pipeline
│ └── dependabot.yml # Automated dependency updates
├── scripts/
│ └── run.sh # Quick start helper
├── PERFORMANCE.md # Benchmark baselines and bottleneck analysis
├── Makefile # Entry point: make run, make test, make clean
├── requirements.txt
├── Dockerfile
└── README.md
| Method | Path | Description |
|---|---|---|
POST |
/v1/upload |
Upload single image |
POST |
/v1/upload/batch |
Upload multiple images (batch) |
POST |
/v1/upload/video |
Upload video — returns per-frame detections with annotated frame images |
POST |
/v1/detect/frame |
Receive a webcam frame and run detection (no disk I/O) |
GET |
/v1/results/{task_id} |
Get batch image results (paginated) |
GET |
/v1/export/{task_id} |
Export batch results as CSV |
GET |
/health |
Health check |
GET |
/metrics |
Prometheus metrics (request count, latency, P99) |
# Health
curl http://localhost:8000/health
# Upload image
curl -X POST -H "X-API-Key: your-api-key" -F "file=@image.jpg" http://localhost:8000/v1/upload
# Batch upload
curl -X POST -H "X-API-Key: your-api-key" -F "files=@img1.jpg" -F "files=@img2.jpg" http://localhost:8000/v1/upload/batch
# Video upload
curl -X POST -H "X-API-Key: your-api-key" -F "file=@video.mp4" http://localhost:8000/v1/upload/video
# Webcam frame
curl -X POST -H "X-API-Key: your-api-key" -F "file=@frame.jpg" http://localhost:8000/v1/detect/frame
# Export CSV
curl -H "X-API-Key: your-api-key" http://localhost:8000/v1/export/<task_id> -o results.csv
# Metrics (Prometheus format)
curl -H "X-API-Key: your-api-key" http://localhost:8000/metrics- Python 3.12+
- 4GB+ RAM recommended (YOLOv8 inference)
- No GPU required (CPU-only PyTorch, works on any machine)
- Webcam required for live detection feature
- Tested on Linux. Windows/macOS should work with minor adjustments.
Alpha — Core detection pipeline is functional with all three input modes (images, video, webcam). Authentication, rate limiting, security headers, metrics, and alerting are all implemented. Test coverage is at 87% with 290 tests across unit, integration, contract, property-based, regression, and fault injection suites.
The following environment variables can be used to configure the application:
| Variable | Default | Description |
|---|---|---|
API_KEY |
(required) | API key for authentication on protected endpoints |
CORS_ORIGINS |
http://localhost:8000 |
Comma-separated list of allowed CORS origins |
RATE_LIMIT |
30 |
Maximum requests per IP per rate window |
RATE_WINDOW |
60 |
Rate limit window in seconds |
UPLOAD_DIR |
uploads |
Directory for uploaded files |
OUTPUT_DIR |
output |
Directory for output files |
YOLO_MODEL |
yolov8n.pt |
YOLOv8 model variant |
A .env.example file is included in the repository. Copy it to .env and adjust values:
cp .env.example .envThe application reads environment variables from .env automatically via pydantic-settings. All values in .env.example are safe to commit — it contains only placeholder keys for local development.
Security note: Never commit the actual
.envfile. Add it to.gitignoreif it isn't already.
Use the staging-specific configuration with automatic TLS, resource limits, and health checks:
# Prerequisites: API_KEY must be set
export API_KEY=$(openssl rand -hex 32)
# Start staging environment (Caddy + App)
docker compose -f deploy/docker-compose.staging.yml up -d
# Verify health status
curl -f http://localhost:8000/health
# View logs
docker compose -f deploy/docker-compose.staging.yml logs -fThe staging compose includes:
- Caddy as reverse proxy with automatic TLS (Let's Encrypt)
- Memory limits (2GB max, 512MB reserved)
- CPU limits (2 cores max, 0.5 reserved)
- Restart policy (
unless-stopped) - Health check every 30s for orchestration
- Logging with rotation (10MB per file, max 3 files)
- Isolated network (bridge)
The .github/workflows/deploy-staging.yml workflow runs automatically
on every push to main:
- Builds the Docker image
- Saves the artifact for deployment
- (Optional) Deploys via SSH to the staging server
Coverage tests run in
.github/workflows/ci.ymland are a prerequisite for the deployment to proceed.
To enable remote deployment, configure the following secrets in GitHub:
STAGING_HOSTSTAGING_USERSTAGING_SSH_KEY
- Generate a strong
API_KEY:openssl rand -hex 32 - Configure
CORS_ORIGINSwith the staging domain - Edit
deploy/Caddyfilewith the real domain - Verify the health check responds
- Monitor
/healthand/metrics
# Roll back to a specific tag or commit
git checkout v0.1.0
docker build -t cortex-vision:v0.1.0 .
docker stop cortex-vision-staging
docker run -d \
--name cortex-vision-staging \
--restart unless-stopped \
-p 8000:8000 \
--env-file .env \
cortex-vision:v0.1.0If using a container registry with tagged images:
docker pull myregistry/cortex-vision:v0.1.0
docker stop cortex-vision-staging
docker run -d --name cortex-vision-staging --restart unless-stopped -p 8000:8000 --env-file .env myregistry/cortex-vision:v0.1.0- Database: The service is stateless with respect to detections — no database migrations to revert.
- Uploaded files: Rollback does not affect previously uploaded files stored in
UPLOAD_DIR/OUTPUT_DIR. - Client compatibility: API changes are versioned under
/v1/. A rollback preserves backward compatibility for existing clients. - Health check: Always verify
/healthafter rollback before directing traffic.
MIT — See LICENSE