An AI-powered intelligent campus surveillance system that performs real-time person detection, stakeholder identification, and unknown person registration using YOLOv8, InsightFace, OpenCV, SQLite, and a Modern WebSocket-driven Dashboard.
-
Check Environment:
python main.py check
-
Launch the Modern Web Dashboard (Recommended):
python main.py web
π Open http://localhost:8001 in your browser for real-time WebSocket video streaming, live visitor notifications, stakeholder management, and analytics.
-
Or Run Surveillance in Terminal Mode:
python main.py run --location "MBUST Lab" -
Bulk Register from Excel/CSV:
python registration/bulk_register.py --sheet stakeholders.xlsx --photos-dir stakeholder
campus_surveillance/
βββ main.py # CLI: init-db | check | register | run | list
βββ requirements.txt
βββ config/settings.py # every path & threshold in one place
βββ camera/webcam_stream.py # laptop webcam (auto-detects index 0/1/2)
βββ detection/person_detector.py # YOLOv8 person detection
βββ recognition/face_recognizer.py # InsightFace embeddings + cosine matching
βββ database/db_manager.py # SQLite: stakeholders, visit_logs, unknown_persons
βββ pipeline/surveillance_pipeline.py # real-time loop
βββ registration/register_stakeholder.py # enroll via webcam or photos
βββ dashboard/app.py # Streamlit dashboard
βββ utils/ # logger + image helpers
βββ models/ # (optional) fine-tuned YOLO weights
βββ data/ # created automatically at runtime
βββ campus_surveillance.db
βββ stakeholders/
βββ unknown_faces/
βββ live/
| Folder | Who fills it | What ends up inside |
|---|---|---|
data/stakeholders/ |
The program, during registration | One reference photo per registered person, named by UID (e.g. S001.jpg). Shown in the dashboard. Don't put files here manually. |
data/unknown_faces/ |
The program, during surveillance | Auto-cropped face images of unrecognized people, timestamped (e.g. unknown_20260704_101502_123456.jpg). Review them in the dashboard's Unknown Persons tab. |
data/live/ |
The program, during surveillance | A single latest.jpg β the most recent annotated frame β which the dashboard's Live Monitor tab displays. Overwritten continuously. |
data/campus_surveillance.db |
The program | The SQLite database (stakeholders, visit logs, unknown records). |
The only folder you create is an optional photos/ folder (anywhere you
like) if you prefer registering people from photo files instead of the
webcam β e.g. photos/sita/1.jpg, 2.jpg, 3.jpg (3β5 clear, front-facing
photos per person give the best accuracy).
- Python 3.9 β 3.11 installed (
python --version) - Internet connection for the first run only (models auto-download:
yolov8n.ptβ 6 MB and InsightFacebuffalo_lβ 280 MB) - Webcam not in use by Zoom/Teams/browser, and OS camera permission granted to your terminal (Windows: Settings β Privacy β Camera; macOS: System Settings β Privacy & Security β Camera)
cd sentinel python -m venv .venv # Windows: .venv\Scripts\activate # macOS / Linux: source .venv/bin/activate pip install -r requirements.txt
python main.py init-db
Creates data/ and all its subfolders + the SQLite database.
python main.py check
Verifies every library, downloads/loads both models, initializes the DB and
tests your webcam. Fix any [FAIL] line before continuing β if this prints
ALL CHECKS PASSED, the pipeline will run without setup errors.
Easiest β straight from the webcam (captures 5 face samples automatically; look at the camera, turn your head slightly between captures):
python main.py register --uid S001 --name "Sita Sharma" --role Student --webcamOr from photo files (file, folder, or glob; multiple photos are averaged into one robust template):
python main.py register --uid F010 --name "Dr. Ram K." --role Faculty --images ./photos/ram/Roles: Student, Faculty, Staff, Authorized.
Re-registering the same --uid safely updates that person.
python main.py list
python main.py run
- A preview window opens: green box = recognized stakeholder (name, role, similarity), red box = UNKNOWN (face auto-saved + DB record).
- Visits are logged at most once per person per 60 s; the same unknown is
not re-saved within 120 s (both tunable in
config/settings.py). - Press q in the preview window (or Ctrl-C in the terminal) to stop.
Useful variants:
python main.py run --location "Home Desk" # label stored with every log python main.py run --source 1 # external USB webcam python main.py run --source test.mp4 --max-frames 300 # evaluate on a video python main.py run --no-display # headless (no preview window)
streamlit run dashboard/app.py
Tabs: Live Monitor (latest annotated frame) β’ Visit Logs (search + CSV export) β’ Unknown Persons (photo review queue with Mark verified) β’ Stakeholders β’ Reports (visits per day / location / role).
source .venv/bin/activate # (or .venv\Scripts\activate) python main.py run # terminal 1 streamlit run dashboard/app.py # terminal 2
| Setting | Default | Effect |
|---|---|---|
FACE_MATCH_THRESHOLD |
0.45 | Lower β easier match (more false accepts); higher β stricter (more false UNKNOWNs). Try 0.40β0.50. |
VISIT_LOG_COOLDOWN_SEC |
60 | Gap between repeat visit logs per person |
UNKNOWN_LOG_COOLDOWN_SEC |
120 | De-dup window for unknown captures |
FRAME_PROCESS_EVERY_N |
2 | Raise to 3β4 on slow laptops for smoother FPS |
DISPLAY_WINDOW |
True | Set False on headless machines |
| Symptom | Fix |
|---|---|
No working webcam found |
Close apps using the camera; grant camera permission to the terminal; try --source 1. |
| First run is very slow | Models are downloading (one time). Watch the progress in the terminal. |
| Everyone shows as UNKNOWN | You skipped Step 4 β the log even warns "gallery is EMPTY". Register people first. |
| You show as UNKNOWN despite being registered | Improve lighting, face the camera, re-register with more/better samples, or lower FACE_MATCH_THRESHOLD slightly. |
| Preview window frozen / won't close | Click the window, press q; or Ctrl-C in the terminal. |
| Dashboard shows "No live frame yet" | Start python main.py run first, then click π Refresh. |
git clone https://github.com/dilliram-code/sentinel.git
cd sentinelpython3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txt
python main.py run --location "MBUST Lab"streamlit run dashboard/app.py
python3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txt
python main.py
streamlit run dashboard/app.py
- Project setup
- Folder structure
- Webcam testing
- YOLO integration
- SQLite database
- Streamlit dashboard
- Stakeholder management
- Unknown person logging
- Multi-camera synchronization
- Person tracking using ByteTrack
- Automatic attendance management
- Visitor management system
- Face search from uploaded image
- REST API backend
- Docker deployment
- Cloud database support
- Role-based authentication
- Heatmap visualization
- Campus movement analytics
- Mobile application
Camera
β
βΌ
YOLOv8
β
βΌ
Detect Person
β
βΌ
Extract Face
β
βΌ
InsightFace
β
βΌ
Embedding
β
βΌ
SQLite Database
β
βΌ
Known?βββββββββββΊYESβββββββββΊVisit Logged
β
βΌ
NO
β
βΌ
Save Unknown Face
β
βΌ
Dashboard Updated
This project demonstrates practical implementation of:
- Computer Vision
- Deep Learning
- Face Recognition
- Object Detection
- Functional Programming
- Database Design
- Streamlit Application Development
- Real-Time Video Processing
- AI System Integration
- Dilli Ram Chaudhary (Master of Artificial Intelligence)
- Piyush Lal Shrestha (Master of Data Science)
- Yalamber Ingnam (Master of Data Science)
Even in a webcam demo, face embeddings are biometric data: enroll only
people who consent, and delete data/ when the demonstration is finished.
This project is developed for academic and research purposes.
β If you find this project helpful, consider giving it a star on GitHubπ!