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.txtpython main.py init-dbCreates data/ and all its subfolders + the SQLite database.
python main.py checkVerifies 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 listpython 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.pyTabs: 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 .venvsource .venv/bin/activatepip install -r requirements.txtpython main.py run --location "MBUST Lab"streamlit run dashboard/app.pypython3 -m venv .venvsource .venv/bin/activatepip install -r requirements.txtpython main.pystreamlit 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😊!