Skip to content

binitp2/Border-Surveillance-Project

Repository files navigation


Border Defence Project Logo



Animated Title




πŸ›‘οΈ An end-to-end AI surveillance pipeline that processes surveillance footage, detects threats using YOLOv8, scores behavioural anomalies, prioritises operational alerts, and surfaces everything in a Streamlit command dashboard β€” with optional Azure cloud integration throughout.


  Live Demo Result (April 2026):  2 persons + 1 vehicle detected Β· 78% avg confidence Β· 18-second end-to-end workflow

πŸ“Œ Table of Contents

Click to expand full contents

🎯 Overview

Border surveillance environments generate large volumes of visual data that are difficult to monitor continuously by hand. This project automates that entire workflow end-to-end.

  Traditional Monitoring                  Border Surveillance AI
  ──────────────────────                  ──────────────────────
  πŸ‘οΈ  1 operator, many cameras             πŸ€–  AI processes all feeds 24/7
  ⏳  Slow, delayed human reaction          ⚑  Sub-second anomaly detection
  ❌  Alert fatigue from false alarms       βœ…  Priority-filtered notifications
  πŸ“  Isolated logs, manual reports         ☁️  Centralised Azure cloud storage
  πŸ“‰  No trend or pattern insights          πŸ“Š  Streamlit operational dashboard

The system accepts a video file or live camera feed, extracts and analyses every frame, assigns anomaly scores, generates prioritised alerts, logs everything locally and optionally to Azure, and makes it all readable through an auto-refreshing dashboard.


🚨 Problem Statement

Domain: Border Defence and Surveillance β€” GTU Internship 2026

Challenge Real-World Impact
Large-scale monitoring Vast border areas exceed human monitoring capacity
Delayed threat detection Manual analysis causes late identification of intrusions
High false-alarm rates Animals, weather, and noise trigger unnecessary responses
Resource constraints Limited manpower must cover extensive remote regions
Siloed data Sensor, camera, and historical data never integrated

This system addresses all five through automated AI detection, cloud integration, and confidence-filtered smart alerting.


🧠 Key Features

πŸ” Object Detection

  • YOLOv8 inference on every extracted frame
  • Detects: person, vehicle, crowd, military_vehicle, aircraft, ship, suspicious_object
  • Structured per-detection output with class, confidence, bounding box, and threat tags
  • has_high and has_critical flags per frame for downstream prioritisation

🧠 Anomaly Detection

  • Baseline learned from first 30 frames (configurable)
  • Isolation Forest scoring on low-dimensional behavioural features
  • Features include detection count, class diversity, confidence stats, motion score, object location, and suspicious class presence
  • Frame-level severity: normal β†’ high β†’ critical

🚨 Smart Alert System

  • Four priority levels: πŸ”΄ CRITICAL / 🟠 HIGH / 🟑 MEDIUM / 🟒 LOW
  • Rolling JSON alert log written locally on every run
  • Cooldown logic to suppress duplicate notifications
  • Email notifications via SendGrid for HIGH and CRITICAL alerts
  • Azure Cosmos DB persistence when credentials are configured

πŸ“Š Operational Dashboard

  • Streamlit command-centre interface
  • Auto-refreshing view of alerts, sessions, and trends
  • Manual email notification trigger from the UI
  • Falls back to demo data when no live pipeline output is present

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                          INPUT LAYER                                     β”‚
β”‚   πŸ“Ή Video File  OR  πŸŽ₯ Live Camera Index  β†’  OpenCV frame reader       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        PREPROCESSING                                     β”‚
β”‚   Resize (640Γ—640) β”‚ Normalize β”‚ Optional Optical Flow (motion score)    β”‚
β”‚   β†’ structured frame_item dicts passed downstream                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     OBJECT DETECTION                  [src/detector.py]  β”‚
β”‚                                                                          β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚   β”‚   YOLOv8 Inference                                                 β”‚ β”‚
β”‚   β”‚   Detects β†’ person β”‚ vehicle β”‚ crowd β”‚ military_vehicle β”‚ aircraft β”‚ β”‚
β”‚   β”‚             ship β”‚ suspicious_object                               β”‚ β”‚
β”‚   β”‚   Output β†’ class Β· confidence Β· bbox Β· threat_tag Β· flags          β”‚ β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     ANOMALY DETECTION                 [src/anomaly.py]   β”‚
β”‚                                                                          β”‚
β”‚   Phase 1: Baseline (frames 1–30) β†’ learn normal behaviour               β”‚
β”‚   Phase 2: Live scoring β†’ Isolation Forest on behavioural features       β”‚
β”‚   Output  β†’ anomaly score β”‚ severity β”‚ human-readable reasons            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    ALERT MANAGEMENT              [src/alert_manager.py]  β”‚
β”‚                                                                          β”‚
β”‚   Score mapping β†’  πŸ”΄ CRITICAL  β”‚  🟠 HIGH  β”‚  🟑 MEDIUM  β”‚  🟒 LOW    β”‚
β”‚   Rolling JSON log  β”‚  Cooldown dedup  β”‚  SendGrid email notifications   β”‚
β”‚   Azure Cosmos DB write (if configured)                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               OUTPUT LAYER + AZURE + DASHBOARD                           β”‚
β”‚                                                                          β”‚
β”‚  πŸ“„ data/alerts/alert_log.json       πŸ—„οΈ  Azure Cosmos DB (alerts)       β”‚
β”‚  πŸ“„ data/results/session_*.json      πŸ“¦  Azure Blob Storage (sessions)  β”‚
β”‚  πŸ–ΌοΈ  data/detections/frame_*.jpg                                        β”‚
β”‚                                                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚             πŸ“Š  Streamlit Dashboard  (dashboard/app.py)          β”‚   β”‚
β”‚  β”‚  Alert feed β”‚ Priority chart β”‚ Session summaries β”‚ Trend lines   β”‚    β”‚
β”‚  β”‚  Anomaly overview β”‚ Manual notify button β”‚ Auto-refresh          β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”„ How It Works

1️⃣ Input and Preprocessing

The pipeline accepts either a video file path or a live camera index. Frames are loaded through OpenCV, resized to 640Γ—640, and optionally passed through an optical flow computation that estimates per-frame motion intensity. Each frame becomes a structured frame_item dictionary passed to downstream modules.

2️⃣ Object Detection

BorderDetector loads the YOLOv8 model once and reuses it across all frames. Each frame produces a list of structured detections with class name, confidence score, bounding box coordinates, normalised spatial features, per-class threat tags, and has_high / has_critical flags for fast downstream filtering.

3️⃣ Anomaly Analysis

AnomalyDetector operates in two phases. The first 30 frames (default) build a normal baseline. Every subsequent frame is scored using Isolation Forest against these behavioural features:

Feature Description
detection_count Total objects detected in the frame
class_diversity Number of unique detected classes
confidence_stats Mean and max detection confidence
critical_class_count Count of high-threat class detections
location_distribution Spatial spread of detected objects
object_size Average bounding box area
motion_score Optical-flow estimated motion intensity
suspicious_presence Binary flag for suspicious class in frame

Frames are classified as normal, high, or critical with human-readable anomaly reasons attached.

4️⃣ Alert Generation

AlertManager maps anomaly output to operational priority levels. HIGH and CRITICAL alerts trigger email notifications subject to a configurable cooldown window. Every non-normal alert is appended to the rolling JSON log. Alert records are optionally written to Azure Cosmos DB.

5️⃣ Storage and Monitoring

Session summaries are saved as timestamped JSON files. When Azure credentials are present, session results are uploaded to Blob Storage and alerts are written to Cosmos DB. The Streamlit dashboard reads local output files directly and auto-refreshes to show the latest operational state.


βš™οΈ Tech Stack

Layer Technology Role
Language Python 3.9+ Core runtime
Object Detection YOLOv8 (Ultralytics) Real-time frame inference
Deep Learning PyTorch 2.x Model backend
Computer Vision OpenCV 4.x Video I/O, frame processing, optical flow
Anomaly Detection scikit-learn (Isolation Forest) Behavioural scoring
Data NumPy, Pandas Feature arrays and session analytics
Dashboard Streamlit + Plotly Operational monitoring UI
Alerting SendGrid Email notifications
Cloud Storage Azure Blob Storage SDK Session result uploads
Cloud Database Azure Cosmos DB SDK Alert persistence
Testing pytest + pytest-cov Automated validation
Environment python-dotenv Credential management

πŸ“‚ Project Structure

Border Surveillance Project/
β”‚
β”œβ”€β”€ πŸ“ src/                           # Core application modules
β”‚   β”œβ”€β”€ pipeline.py                   # Main orchestration entry point
β”‚   β”œβ”€β”€ detector.py                   # YOLOv8 wrapper + structured detections
β”‚   β”œβ”€β”€ anomaly.py                    # Baseline learning + Isolation Forest scoring
β”‚   β”œβ”€β”€ alert_manager.py              # Priority assignment, logging, email, cooldown
β”‚   └── azure_client.py              # Blob Storage + Cosmos DB integration
β”‚
β”œβ”€β”€ πŸ“ dashboard/
β”‚   β”œβ”€β”€ app.py                        # Streamlit command-centre dashboard
β”‚   └── Border Defence AI logo.png    # Project branding asset
β”‚
β”œβ”€β”€ πŸ“ scripts/                       # Utility and dataset preparation scripts
β”‚   β”œβ”€β”€ main.py                       # Minimal detector demo over a test video
β”‚   β”œβ”€β”€ pilot.py                      # Manual integration checker across all modules
β”‚   β”œβ”€β”€ smoke_test.py                 # Quick pipeline smoke test
β”‚   β”œβ”€β”€ generate_test_video.py        # Synthetic test video generator
β”‚   β”œβ”€β”€ preprocess_all_datasets.py    # Full dataset preprocessing
β”‚   β”œβ”€β”€ preprocess_local.py           # Local dataset preprocessing
β”‚   β”œβ”€β”€ convert_xview_to_yolo.py      # xView β†’ YOLO format converter
β”‚   β”œβ”€β”€ xview_geojson_to_yolo.py      # xView GeoJSON β†’ YOLO labels
β”‚   β”œβ”€β”€ fix_xview_patch.py            # xView patch correction utility
β”‚   β”œβ”€β”€ fix_vedai_crowd.py            # VEDAI crowd class fix
β”‚   └── smart_extract.py             # Intelligent frame extractor
β”‚
β”œβ”€β”€ πŸ“ data/                          # Runtime data (gitignored β€” not in repo)
β”‚   β”œβ”€β”€ alerts/                       # alert_log.json β€” rolling alert output
β”‚   β”œβ”€β”€ results/                      # session_*.json β€” per-run summaries
β”‚   β”œβ”€β”€ test_videos/                  # Sample videos for local runs
β”‚   β”œβ”€β”€ processed/                    # Preprocessed training-ready data
β”‚   β”œβ”€β”€ annotations/                  # Dataset annotation files
β”‚   β”œβ”€β”€ raw/                          # Source datasets
β”‚   └── logs/                         # Pipeline runtime logs
β”‚
β”œβ”€β”€ πŸ“ tests/                         # Automated test suite
β”‚   β”œβ”€β”€ test_detector.py
β”‚   β”œβ”€β”€ test_anomaly_and_alert.py
β”‚   └── test_pipeline.py
β”‚
β”œβ”€β”€ πŸ“ models/                        # YOLO weights + anomaly model artefacts
β”œβ”€β”€ πŸ“ notebooks/                     # EDA and experimentation notebooks
β”œβ”€β”€ πŸ“ docs/                          # Architecture diagrams + presentations
β”œβ”€β”€ πŸ“ overview/                      # Implementation guide and references
β”‚
β”œβ”€β”€ πŸ“ models/                        # Trained model artefacts (committed to repo)
β”‚   β”œβ”€β”€ border_yolo.pt                # Custom-trained YOLOv8 border detection model (~22 MB)
β”‚   └── anomaly_model.pkl            # Trained Isolation Forest anomaly detector (99 KB)
β”‚
β”œβ”€β”€ yolov8n.pt                        # YOLOv8 nano base weights (fallback)
β”œβ”€β”€ yolov8s.pt                        # YOLOv8 small base weights (fallback)
β”œβ”€β”€ requirements.txt                  # All Python dependencies
β”œβ”€β”€ pyproject.toml                    # Project metadata
β”œβ”€β”€ pytest.ini                        # Test runner configuration
β”œβ”€β”€ makefile                          # Common task shortcuts
β”œβ”€β”€ .env                              # Local credentials (never committed)
β”œβ”€β”€ .gitignore                        # Excludes data/, venv/, .env
└── README.md                         # This file

▢️ Quick Start β€” Evaluator Guide

⏱️ Estimated setup time: ~5 minutes. Follow these six steps in order and the system will run end-to-end from video input to a live dashboard.


Step 1 β€” Clone the Repository

git clone https://github.com/binitp2/Border-Surveillance-Project.git
cd "Border-Surveillance-Project"

Step 2 β€” Create and Activate a Virtual Environment

python -m venv venv

# Linux / macOS
source venv/bin/activate

# Windows PowerShell
venv\Scripts\Activate.ps1

# Windows CMD
venv\Scripts\activate.bat

Step 3 β€” Install All Dependencies

pip install --upgrade pip
pip install -r requirements.txt

πŸ’‘ Dependencies installed. Now verify your trained models are present before running.


Step 3.5 β€” Verify Trained Models Are Present

After cloning, confirm the models/ folder contains both trained artefacts:

models/
β”œβ”€β”€ border_yolo.pt       ← Custom-trained YOLOv8 border detection model (~22 MB)
└── anomaly_model.pkl    ← Trained Isolation Forest anomaly detector (99 KB)

βœ… Both files are committed directly to the repository β€” no separate download needed. The pipeline loads models/border_yolo.pt for detection and models/anomaly_model.pkl for anomaly scoring automatically. If border_yolo.pt is missing, the pipeline falls back gracefully to yolov8n.pt (base YOLO weights in repo root).


Step 4 β€” Configure Environment Variables

Create a .env file in the project root. Azure and SendGrid fields are optional β€” leave them blank to run the system in fully local mode.

# ── Azure Storage ──────────────────────────────────
AZURE_STORAGE_CONNECTION_STRING=
AZURE_STORAGE_CONTAINER_ALERTS=alert-frames
AZURE_STORAGE_CONTAINER_RESULTS=session-results

# ── Azure Cosmos DB ────────────────────────────────
AZURE_COSMOS_ENDPOINT=
AZURE_COSMOS_KEY=
AZURE_COSMOS_DATABASE=SurveillanceDB
AZURE_COSMOS_CONTAINER=Alerts

# ── Email Alerts (SendGrid) ────────────────────────
SENDGRID_API_KEY=
ALERT_FROM_EMAIL=
ALERT_TO_EMAIL=

# ── Email Alerts (SMTP fallback) ───────────────────
SMTP_USER=
SMTP_APP_PASSWORD=

# ── Dashboard (only if running outside project root)
DATA_ROOT=

βœ… The full pipeline β€” detection, anomaly scoring, alerts, dashboard β€” works entirely without cloud credentials. All outputs are saved locally.


Step 4.5 β€” Download Required Data Files (Important)

⚠️ Some files are excluded from the repository using .gitignore (e.g., large .mp4 videos and dataset configs). You must download them before running the pipeline.

⬇️ Download Data & Test files

πŸ“ After Download β€” Place Files Here

data/
β”œβ”€β”€ test_videos/
β”‚   └── dota_aerial_test.mp4
└── processed/
    └── data.yaml

Step 5 β€” Run the AI Pipeline

Recommended evaluation command:

python src/pipeline.py --video data/test_videos/dota_aerial_test.mp4 --save-frames

With additional controls:

python src/pipeline.py \
  --video data/test_videos/dota_aerial_test.mp4 \
  --frame-skip 3 \
  --save-frames \
  --results-dir data/results \
  --annotated-dir data/detections

Live camera mode:

python src/pipeline.py --camera 0

Expected terminal output:

βœ… Preprocessing complete   β€” frames extracted and resized to 640Γ—640
βœ… Detection complete       β€” structured detections logged per frame
βœ… Anomaly scoring complete β€” Isolation Forest scored all frames
βœ… Alerts generated         β€” priority levels assigned and logged
βœ… Session saved            β€” data/results/session_<source>_<timestamp>.json
βœ… Alert log written        β€” data/alerts/alert_log.json

Step 6 β€” Launch the Dashboard

streamlit run dashboard/app.py

Open your browser at http://localhost:8501 to see the live operational command-centre view.


Step 7 β€” Run the Test Suite (optional but recommended)

# All tests with verbose output
pytest tests -v

# With HTML coverage report
pytest tests --cov=src --cov-report=html
# Report opens at: htmlcov/index.html

πŸ” Other Useful Entry Points

Command Purpose
python scripts/main.py Minimal single-video detector demo
python scripts/pilot.py data/test_videos/dota_aerial_test.mp4 Manual integration check across all modules
python scripts/smoke_test.py Fast pipeline smoke test
python scripts/generate_test_video.py Generate a synthetic test video if none is present

☁️ Azure Integration

When credentials are present in .env, two cloud paths activate automatically β€” no code changes required.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Azure Services Used                                                 β”‚
β”‚                                                                      β”‚
β”‚  πŸ“¦ Blob Storage   β†’ session result JSON files uploaded per run     β”‚
β”‚                      Container: session-results                      β”‚
β”‚                                                                      β”‚
β”‚  πŸ—„οΈ  Cosmos DB      β†’ individual alert documents written per event  β”‚
β”‚                      Database: SurveillanceDB                        β”‚
β”‚                      Container: Alerts                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

If Azure credentials are missing or invalid, the system falls back silently to local-only mode. No errors are raised and the pipeline continues normally.

Data stored in Azure per run:

  • Session result summary (session_<source>_<timestamp>.json) β†’ Blob Storage
  • Per-alert records with priority, anomaly score, detection count, motion score, and reasons β†’ Cosmos DB

πŸ“§ Alert System

The alerting layer is designed for operational triage, not raw event dumping.

Priority Trigger Condition Notification Behaviour
πŸ”΄ CRITICAL Highest-severity anomaly + critical class detection Email sent immediately
🟠 HIGH Significant anomaly score or critical class flag Email sent (cooldown applies)
🟑 MEDIUM Lower anomaly score or motion-based escalation Written to log only
🟒 LOW Normal or near-normal activity Written to log only
  • All non-normal alerts are appended to data/alerts/alert_log.json
  • HIGH and CRITICAL alerts trigger SendGrid email when SENDGRID_API_KEY is configured
  • A cooldown window suppresses repeated notifications for the same ongoing threat pattern
  • Manual notification can be triggered at any time directly from the Streamlit dashboard

πŸ“Š Dashboard

dashboard/app.py provides a command-centre style operational view over all pipeline output.

Panel What You See
πŸ“‹ Recent Alerts Sortable feed of latest alerts with colour-coded priority badges
πŸ₯§ Priority Distribution Pie and bar chart breakdown of CRITICAL / HIGH / MEDIUM / LOW
πŸ“ˆ Anomaly Trend Score-over-time chart for the most recent session
πŸ“¦ Session Summaries Per-run statistics read from data/results/session_*.json
πŸ” Detection Activity Detection count and class distribution trends
πŸ”” Notification Status SendGrid readiness indicator + manual email trigger button

Primary data inputs:

data/alerts/alert_log.json
data/results/session_*.json
data/detections/anomaly_summary.json    ← optional

If no live pipeline output is present, the dashboard automatically falls back to demo data so the interface always remains fully functional and reviewable.


🧩 Key Modules

src/pipeline.py

Main orchestration layer. Connects preprocessing β†’ detection β†’ anomaly scoring β†’ alert management in a single runtime session. Saves session summaries and optionally annotated frames, then uploads to Azure when configured.

src/detector.py

YOLOv8 wrapper. Loads the model once per session and reuses it across all frames. Converts raw model output into structured Detection objects carrying class, confidence, bbox, threat tags, and frame-level has_high / has_critical flags.

src/anomaly.py

Two-phase runtime: baseline collection from the first 30 frames, then Isolation Forest live scoring for all subsequent frames. Produces interpretable anomaly reasons and severity classifications attached to each scored frame result.

src/alert_manager.py

Priority assignment from anomaly level and motion score. Maintains the rolling JSON alert log with append-only writes. Sends SendGrid notifications for HIGH+ events within cooldown constraints. Writes alert records to Cosmos DB via azure_client.

src/azure_client.py

Lazy initialisation β€” Azure clients are created only when valid credentials are present. Uploads session JSON files to Blob Storage. Writes alert documents to Cosmos DB. Falls back gracefully to a no-op if Azure is unavailable, with no pipeline interruption.

dashboard/app.py

Reads alert_log.json and session_*.json from local data/ directories. Auto-refreshes on a configurable interval. Renders alert feed, priority charts, session summaries, anomaly trend, and manual notification control.


πŸ§ͺ Sample Output & Results

Example alert record written to data/alerts/alert_log.json:

{
  "alert_id": "alert_1712312345678",
  "frame_id": 42,
  "priority": "HIGH",
  "alert_level": "high",
  "anomaly_score": -0.1042,
  "detection_count": 7,
  "motion_score": 10.4,
  "reasons": ["crowd gathering detected"],
  "notified": true
}

Example session summary written to data/results/session_dota_aerial_test_20260405_144229.json:

{
  "source": "dota_aerial_test.mp4",
  "timestamp": "2026-04-05T14:42:29",
  "total_frames": 124,
  "frames_scored": 94,
  "critical_alerts": 1,
  "high_alerts": 3,
  "medium_alerts": 8,
  "low_alerts": 82,
  "avg_anomaly_score": -0.073,
  "avg_confidence": 0.78,
  "azure_uploaded": true
}

Typical output file set after a single pipeline run:

data/alerts/alert_log.json
data/results/session_<source>_<timestamp>.json
data/detections/frame_000042.jpg         ← if --save-frames enabled
data/logs/pipeline.log
runs/detect/                             ← YOLO inference artefacts

Live demo results β€” Final presentation, April 2026:

Upload video β†’ Azure Blob trigger β†’ YOLOv8 inference β†’ Cosmos DB write β†’ Email alert
Total end-to-end time   : 18 seconds
Objects detected        : 2 persons Β· 1 vehicle
Average confidence      : 78%
Dashboard refresh time  : < 5 seconds

🧾 Testing

The project includes an automated test suite covering all major runtime modules.

# Run full suite with verbose output
pytest tests -v

# Run with HTML coverage report
pytest tests --cov=src --cov-report=html
# Open: htmlcov/index.html in your browser

# Run individual test files
pytest tests/test_detector.py -v
pytest tests/test_anomaly_and_alert.py -v
pytest tests/test_pipeline.py -v
Test File Coverage Area
test_detector.py YOLOv8 model loading, inference execution, structured detection output format
test_anomaly_and_alert.py Baseline learning, Isolation Forest scoring, priority assignment logic, alert log writes
test_pipeline.py End-to-end orchestration, output file creation, inter-module integration

πŸ“ˆ Future Improvements

  • Stronger model and version tracking for reproducible production deployments
  • REST API layer to expose pipeline controls programmatically
  • Alert frame thumbnails with direct Azure Blob links embedded in dashboard views
  • Automated CI/CD deployment profiles for staging and production environments
  • Multi-camera ingestion with centralised alert aggregation across feeds
  • Custom YOLOv8 fine-tuning on annotated border-specific datasets (VEDAI, xView, DOTA)
  • Real-time streaming support via RTSP or WebRTC camera feeds

πŸŽ“ Academic Context

Field Detail
Program Microsoft Elevate β€” GTU Internship 2026
Powered By Edunet Foundation & FICE Education
College Government Engineering College, Bharuch Research
Department Computer Engineering
Semester 8th Semester
Duration January 2026 β€” April 2026 (12 weeks Β· 420 hours)
Problem Domain Border Defence and Surveillance (GTU)

GTU domain requirements fulfilled by this project:

  • βœ… EDA on surveillance and sensor datasets
  • βœ… Anomaly detection model to identify unusual activity patterns
  • βœ… ML/DL object classification of movement patterns using YOLOv8
  • βœ… Alert prioritisation system that reduces false positives via confidence filtering
  • βœ… Cloud-based data integration using Microsoft Azure (Blob Storage + Cosmos DB)

πŸ‘¨β€πŸ’» Author

Field Detail
Name Binit Patel (Binit Patel)
Role Intern
Enrollment 230143107014
Linkedin @binitpatel
Internal Guide Prof. Namrata Shroff
External Guide Adarsh Gupta

πŸ“¬ Need Help?

If you face any issues while setting up or running the project, feel free to reach out.


πŸ“œ License

This project is distributed under the MIT License β€” see LICENSE for full details.


⭐ If this project was useful, please consider starring the repository!

Built with ❀️ by Binit Patel · Microsoft Elevate Internship 2026 · Government Engineering College, Bharuch

About

πŸ›‘οΈ AI-Powered Border Surveillance System | Real-Time Anomaly Detection + YOLOv8 Object Detection + Azure Cloud + Streamlit Dashboard | GTU Internship Project 2026

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors