π‘οΈ 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
Click to expand full contents
- π― Overview
- π¨ Problem Statement
- π§ Key Features
- ποΈ System Architecture
- π How It Works
- βοΈ Tech Stack
- π Project Structure
βΆοΈ Quick Start β Evaluator Guide- βοΈ Azure Integration
- π§ Alert System
- π Dashboard
- π§© Key Modules
- π§ͺ Sample Output & Results
- π§Ύ Testing
- π Future Improvements
- π Academic Context
- π¨βπ» Author
- π License
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.
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.
|
|
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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 β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
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.
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.
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.
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.
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.
| 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 |
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
β±οΈ 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.
git clone https://github.com/binitp2/Border-Surveillance-Project.git
cd "Border-Surveillance-Project"python -m venv venv
# Linux / macOS
source venv/bin/activate
# Windows PowerShell
venv\Scripts\Activate.ps1
# Windows CMD
venv\Scripts\activate.batpip install --upgrade pip
pip install -r requirements.txtπ‘ Dependencies installed. Now verify your trained models are present before running.
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.ptfor detection andmodels/anomaly_model.pklfor anomaly scoring automatically. Ifborder_yolo.ptis missing, the pipeline falls back gracefully toyolov8n.pt(base YOLO weights in repo root).
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.
β οΈ Some files are excluded from the repository using.gitignore(e.g., large.mp4videos and dataset configs). You must download them before running the pipeline.
data/
βββ test_videos/
β βββ dota_aerial_test.mp4
βββ processed/
βββ data.yamlRecommended evaluation command:
python src/pipeline.py --video data/test_videos/dota_aerial_test.mp4 --save-framesWith 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/detectionsLive camera mode:
python src/pipeline.py --camera 0Expected 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
streamlit run dashboard/app.pyOpen your browser at http://localhost:8501 to see the live operational command-centre view.
# 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| 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 |
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
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_KEYis 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/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.
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.
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.
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.
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.
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.
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.
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
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 |
- 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
| 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)
| Field | Detail |
|---|---|
| Name | Binit Patel (Binit Patel) |
| Role | Intern |
| Enrollment | 230143107014 |
| @binitpatel | |
| Internal Guide | Prof. Namrata Shroff |
| External Guide | Adarsh Gupta |
If you face any issues while setting up or running the project, feel free to reach out.
This project is distributed under the MIT License β see LICENSE for full details.