Skip to content

satvikdua06-dev/IoT-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛡️ Campus Zone Surveillance & AI Violation Detection

Python YOLOv8 Flask ThingSpeak

A high-performance IoT security solution designed for campus environments. Using real-time Computer Vision (YOLOv8), this system monitors multiple security zones, enforces time-based restrictions, manages approved night extensions, and synchronizes data with cloud IoT platforms.


🏗️ System Architecture

graph TD
    A[Webcam 0] --> CM[Shared Camera Manager]
    B[Webcam 1] --> CM
    CM --> D1[Detector: Library]
    CM --> D2[Detector: IOT Lab]
    CM --> D3[Detector: Seminar Hall]
    
    D1 & D2 & D3 --> YOLO{YOLOv8 Engine}
    YOLO --> Logic{Permission Logic}
    
    Logic -->|Allowed| Dash[Dashboard - PERMITTED]
    Logic -->|Restricted| DB[(SQLite DB)]
    Logic -->|Restricted| MQTT[MQTT Broker]
    Logic -->|Restricted| TS[ThingSpeak Cloud]
    
    DB --> Dash
    Dash -->|Video Switching| CM
Loading

🌟 Advanced Features

🧵 Shared Camera Manager (Threading)

On Windows systems, hardware access to webcams is exclusive to a single thread/process. This project implements a Singleton Camera Manager that:

  • Opens exactly one cv2.VideoCapture per physical index.
  • Uses a dedicated high-speed grabber thread to maintain a thread-safe frame buffer.
  • Allows an unlimited number of concurrent YOLO detectors to "subscribe" to the same feed without any hardware conflicts or latency spikes.

🌙 Smart Night Extensions

Unlike traditional security systems that are either ON or OFF, this system supports Permission Overrides:

  • Database-Driven: Checks the extensions table for approved student/staff IDs and timestamps.
  • Context Awareness: If a detection occurs at 1 AM in a restricted lab, but a "Project Deadline" extension exists, the system automatically marks it as a permitted visit instead of an intrusion.

📊 IoT Data Pipeline

  • ThingSpeak Integration: Automatically synchronizes detection events (Zone ID, Confidence, Hour of detection) to your cloud dashboard for long-term analytics.
  • MQTT Telemetry: Publishes standardized JSON payloads to campus/zone/<id>/detection for integration with smart sirens or mobile notification apps.

🖥️ Web Dashboard

The system features a modern, glassmorphism-inspired dashboard that provides:

  • Live Stream Switching: Click any zone card to instantly swap the main monitor feed.
  • Real-time Badges: Visual indicators for "Extension Active" (including reason strings), "Intrusion Detected", and "Area Clear".
  • Dynamic Logging: Automatic updates for the violation history table using AJAX polling.

🛠️ API Reference

GET /api/zones

Returns the current status of all monitored zones, including active extensions and recent detection summaries.

GET /api/events

Returns the last 20 detection events (Violations vs Permitted Entries).

POST /api/zones/<zid>/config

Allows remote updates to the allowed start/end times and webcam index for a specific zone.


📋 Database Schema

zones

Column Type Description
zone_id TEXT (PK) Unique identifier (e.g., zone_lib)
zone_name TEXT Human-readable name
zone_type TEXT time_restricted or forbidden_permanent
allowed_start TEXT Base permitted hour (e.g., 09:00)
allowed_end TEXT Base closing hour (e.g., 21:00)
webcam_index INT Hardware camera ID (0 or 1)

extensions

Column Type Description
zone_id TEXT Linked zone
ext_date TEXT Specific date for the extension
ext_start TEXT Start of extension window
ext_end TEXT End of extension window
reason TEXT Purpose (e.g., "AI Training")

🚀 Setup & Installation

  1. Clone & Install:

    git clone https://github.com/satvikdua06-dev/IoT-Project.git
    pip install -r requirements.txt
  2. Environment Variables (.env):

    THINGSPEAK_WRITE_API_KEY=your_key
    MQTT_BROKER=broker.hivemq.com
    DETECTION_COOLDOWN_SECONDS=10
  3. Launch:

    python app.py

🛡️ Troubleshooting

  • Missing Models: The YOLOv8n权重 file (yolov8n.pt) will automatically download on first run (approx 6MB).
  • Hardware Issues: If a webcam is disconnected, the Shared Camera Manager will gracefully log an error and display a "Camera Offline" placeholder on the dashboard.
  • Port Conflicts: By default, the server runs on port 5050. If this is occupied, update FLASK_PORT in your .env.

🤝 Contributions & License

Made by Satvik Dua. Distributed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors