Skip to content

About

Attendence System by Facial Recognition

Resources

Stars

4 stars

Watchers

1 watching

Forks

Latest commit

ย 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฏ Face Recognition Attendance System

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


๐Ÿ“Œ Project Overview

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.

Core Workflow

Student Registration
        โ†“
Capture Face Samples
        โ†“
Store Face Data
        โ†“
Train KNN Classifier
        โ†“
Real-Time Face Detection
        โ†“
Face Recognition
        โ†“
Student Identification
        โ†“
Attendance Recorded
        โ†“
Daily CSV Report

โœจ Features

๐Ÿ‘ค Face Registration

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.


๐Ÿค– Face Recognition

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.


๐Ÿ• Automated Attendance

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.


๐Ÿ”Š Voice Confirmation

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.


๐Ÿ“Š Attendance Dashboard

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.


๐Ÿ› ๏ธ Tech Stack

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.


๐Ÿ“‚ Project Structure

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.


โš™๏ธ How It Works

Step 1 โ€” Register a Student

Run:

python add_faces.py

Enter 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

Step 2 โ€” Start Face Recognition

Run:

python test.py

The program:

  1. Opens the webcam
  2. Detects faces
  3. Loads registered face data
  4. Trains a KNN classifier
  5. Predicts the detected student's name
  6. Displays the recognized name on the video feed
  7. Records attendance when the attendance key is pressed

The current implementation uses:

KNeighborsClassifier(n_neighbors=5)

for classification.


Step 3 โ€” Mark Attendance

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.


Step 4 โ€” View Attendance

Run the Streamlit application:

streamlit run app.py

The dashboard loads the current day's attendance CSV and displays the records in a table.


๐Ÿง  Machine Learning Approach

The project uses a K-Nearest Neighbors (KNN) classifier.

Training

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.


๐Ÿ“ธ Face Detection

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 Data Format

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-21

This makes the records easy to open and analyze using Excel, Pandas, or other data-analysis tools.


๐Ÿ–ฅ๏ธ Basic Web Portal

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.


๐Ÿš€ Installation

Prerequisites

Make sure you have:

  • Python 3.x
  • Webcam
  • Windows OS recommended for voice feedback
  • Git

Clone the Repository

git clone https://github.com/Lakshya172/Attendence-System.git

Navigate to the project:

cd Attendence-System

Install Dependencies

pip install opencv-python
pip install numpy
pip install pandas
pip install scikit-learn
pip install streamlit
pip install streamlit-autorefresh
pip install pywin32

โ–ถ๏ธ Running the Project

Register a Student

python add_faces.py

Start Recognition

python test.py

Start Attendance Dashboard

streamlit run app.py

โš ๏ธ Important Notes

Camera Required

The system uses:

cv2.VideoCapture(0)

so a working webcam is required.

Windows Voice Support

The current recognition script uses:

from win32com.client import Dispatch

for Windows SAPI voice output, so this feature is intended for Windows environments.

Local Data Storage

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.


๐Ÿ”ฎ Future Improvements

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

๐ŸŽ“ Learning Outcomes

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

๐Ÿ‘จโ€๐Ÿ’ป Author

Lakshya Agarwal

B.Tech Computer Science & Engineering Lovely Professional University

GitHub: https://github.com/Lakshya172


โญ Project

If you find this project useful, consider giving the repository a โญ.

Repository: https://github.com/Lakshya172/Attendence-System


๐Ÿ“„ License

This project was created for educational and learning purposes.

About

Attendence System by Facial Recognition

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages