A Python-based automated attendance management system that uses computer vision and machine learning to identify students through facial recognition and record their attendance with timestamps.
The system captures facial samples through a webcam, trains a K-Nearest Neighbors (KNN) classifier, recognizes registered students in real time, and stores daily attendance records in CSV files
Traditional attendance systems require teachers to manually call names or maintain physical registers, which can be time-consuming and prone to human error.
This project automates the process using face detection and face recognition.
A student can register their face once, after which the system can identify them through a webcam and record their attendance along with the exact time.
Student Registration
โ
Capture Face Samples
โ
Store Face Data
โ
Train KNN Classifier
โ
Real-Time Face Detection
โ
Face Recognition
โ
Student Identification
โ
Attendance Recorded
โ
Daily CSV Report
The system allows a new student to register by entering their name and capturing facial samples through the webcam.
During registration:
- Webcam captures the student's face
- Haar Cascade detects the face
- Face images are cropped and resized
- 100 facial samples are collected
- Facial data is stored locally
- Student names are associated with the captured samples
The registration process is implemented in add_faces.py.
The system uses:
- OpenCV for webcam input and face detection
- Haar Cascade Classifier for detecting faces
- KNN for identifying registered students
During recognition, the detected face is resized to the same dimensions used during training and passed to the KNN classifier to predict the student's identity.
Once a student is recognized, the system generates an attendance record containing:
NAME
TIME
Attendance is stored in a daily CSV file using the format:
Attendance/Attendance_DD-MM-YYYY.csv
This creates a separate attendance file for each day.
The system uses Windows Speech API through win32com.client to provide voice feedback when attendance is taken.
For example:
"Attendance Taken.."
This gives the user an audio confirmation after pressing the attendance key.
A Streamlit-based application is included for displaying the attendance data.
The application automatically loads the CSV corresponding to the current date and displays the records using a Streamlit dataframe.
| Technology | Purpose |
|---|---|
| Python | Core programming language |
| OpenCV | Webcam processing and computer vision |
| Haar Cascade | Face detection |
| Scikit-learn | KNN machine-learning classifier |
| NumPy | Numerical and matrix operations |
| Pandas | Attendance data handling |
| Pickle | Local face/label data storage |
| CSV | Attendance record storage |
| Streamlit | Attendance dashboard |
| PyWin32 | Voice feedback through Windows SAPI |
| HTML/CSS/JavaScript | Basic attendance portal interface |
The repository includes Python scripts for registration, recognition, testing, and the Streamlit viewer, along with a basic web portal.
Attendence-System/
โ
โโโ Attendance/
โ โโโ Attendance_DD-MM-YYYY.csv
โ
โโโ data/
โ โโโ haarcascade_frontalface_default.xml
โ โโโ names.pkl
โ โโโ faces_data.pkl
โ
โโโ Attendance/
โ
โโโ Login.html
โโโ main.html
โโโ script.js
โโโ stylee.css
โ
โโโ add_faces.py
โโโ app.py
โโโ test.py
โ
โโโ xyz.jpg
โโโ xyzz.png
โ
โโโ README.md
The current repository contains the Attendance and data directories along with the Python scripts and web-interface files shown above.
Run:
python add_faces.pyEnter the student's name when prompted:
Enter Your Name:
The webcam opens and captures up to 100 face samples for the student.
The captured data is stored in:
data/faces_data.pkl
and the corresponding names are stored in:
data/names.pkl
Run:
python test.pyThe program:
- Opens the webcam
- Detects faces
- Loads registered face data
- Trains a KNN classifier
- Predicts the detected student's name
- Displays the recognized name on the video feed
- Records attendance when the attendance key is pressed
The current implementation uses:
KNeighborsClassifier(n_neighbors=5)for classification.
When the student's face is recognized, press:
O
The system provides voice confirmation and writes the student's name and timestamp into the day's attendance CSV file.
Press:
Q
to exit the recognition window.
Run the Streamlit application:
streamlit run app.pyThe dashboard loads the current day's attendance CSV and displays the records in a table.
The project uses a K-Nearest Neighbors (KNN) classifier.
Registered face images are:
Face Image
โ
Face Detection
โ
Crop Face
โ
Resize โ 50 ร 50
โ
Flatten Pixel Values
โ
KNN Training Data
The training data and labels are loaded from:
faces_data.pkl
names.pkl
The KNN model is configured with:
KNeighborsClassifier(n_neighbors=5)and trained using the stored face matrix and corresponding labels.
The project uses OpenCV's Haar Cascade classifier:
data/haarcascade_frontalface_default.xml
The webcam frame is converted to grayscale before face detection:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)The detected face is then cropped and resized before being passed to the recognition pipeline.
Attendance is stored as CSV files:
Attendance/
โโโ Attendance_15-08-2026.csv
โโโ Attendance_16-08-2026.csv
โโโ Attendance_17-08-2026.csv
Each file contains:
NAME,TIME
Lakshya,10:30-15
Rahul,10:32-08
Aman,10:34-21This makes the records easy to open and analyze using Excel, Pandas, or other data-analysis tools.
The repository also contains a basic attendance portal built with HTML, CSS, and JavaScript.
The portal provides two primary actions:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Attendance Portal โ
โ โ
โ [ Mark Attendance ] โ
โ โ
โ [ New Registration ] โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The interface is implemented through main.html, script.js, and stylee.css.
Make sure you have:
- Python 3.x
- Webcam
- Windows OS recommended for voice feedback
- Git
git clone https://github.com/Lakshya172/Attendence-System.gitNavigate to the project:
cd Attendence-Systempip install opencv-python
pip install numpy
pip install pandas
pip install scikit-learn
pip install streamlit
pip install streamlit-autorefresh
pip install pywin32python add_faces.pypython test.pystreamlit run app.pyThe system uses:
cv2.VideoCapture(0)so a working webcam is required.
The current recognition script uses:
from win32com.client import Dispatchfor Windows SAPI voice output, so this feature is intended for Windows environments.
Face data is stored locally using Pickle files:
data/names.pkl
data/faces_data.pkl
Attendance records are stored as CSV files rather than in a cloud database.
The project can be extended into a production-ready attendance platform by adding:
- MongoDB/PostgreSQL database
- Secure user authentication
- Teacher/admin dashboard
- Student dashboard
- Attendance percentage calculation
- Monthly and semester reports
- Duplicate attendance prevention
- Email notifications
- Cloud storage
- REST API
- Mobile application
- Better face-recognition models
- Liveness detection
- Role-based access control
- Export reports to Excel/PDF
- Deploy the dashboard online
Through this project, I gained practical experience with:
- Computer Vision
- Face Detection
- Face Recognition
- Machine Learning Classification
- OpenCV
- KNN Algorithm
- Webcam Processing
- Python File Handling
- CSV Data Management
- Pickle Serialization
- Streamlit
- Basic Web Development
- Real-time Application Development
Lakshya Agarwal
B.Tech Computer Science & Engineering Lovely Professional University
GitHub: https://github.com/Lakshya172
If you find this project useful, consider giving the repository a โญ.
Repository: https://github.com/Lakshya172/Attendence-System
This project was created for educational and learning purposes.