Back to projects
Jeff G. Njoroge
Face Recognition Attendance System
Year: 2023 PythonFlaskOpenCVNumPyPandasscikit-learnKNNJoblibJinja2Bootstrap
A Python/Flask web application that captures student face images, trains a lightweight face classifier, and uses a live webcam feed to mark attendance automatically during a lecture. The system is designed for a lecturer workflow: enter unit details, enroll students, then run recognition to log attendance with timestamps.
The core idea is simple and fully local: student face images are collected via the webcam, a K-Nearest Neighbors (KNN) model is trained from those images, and recognized identities are written into a daily attendance file for the selected unit.
Key features:
- Lecture/session setup: Lecturer enters session context (e.g., lecturer name and unit details) and the system starts a new daily attendance run for that class.
- Student enrollment: Captures multiple face samples per student from a webcam and builds a labeled dataset for recognition.
- Model training and persistence: Trains a scikit-learn KNN classifier on standardized face crops and persists the trained model for reuse.
- Live recognition + attendance logging: Detects faces in real time from the webcam feed, predicts an identity, and logs attendance with a timestamp.
- Attendance viewing: Renders the current session’s attendance records in a simple web UI table.
- Lightweight “directory” view: Provides a quick view of enrolled identities (no external database required).
- User removal: Supports removing an identity and its associated training data, and updates logs accordingly.
How it works (high-level):
- Face detection: Each frame is converted to grayscale and faces are located using a Haar Cascade classifier.
- Face preprocessing: Detected face regions are resized to (50 \times 50) and flattened into a feature vector.
- Classification: A KNN model predicts the closest known identity label from the training set.
- Attendance storage: Attendance is written to a per-class, per-day CSV log with
Name,ID, andTimecolumns. The app avoids duplicate entries for the same ID within a session/day.
Notes/assumptions:
- The app is intended to run on a machine with a webcam and a GUI environment (OpenCV window is used for live capture/recognition).
- All data (face images, trained model, attendance CSVs) is stored locally in the project’s filesystem; no external database is required.