Face Recognition Attendance System'

Face Recognition Attendance System with Python Django

Looking for a real-time attendance system using facial recognition? This post will guide you through building a simple but effective Face Recognition Attendance System using Python, Django, and OpenCV


๐Ÿงฐ Tech Stack Overview

Technology Purpose
Python Core programming language
Django Web framework for routing/views/forms
OpenCV Face detection and recognition
Pandas Handle CSV read/write for attendance
Pillow (PIL) Image processing during training
HTML/CSS (basic) Frontend forms and attendance table display

๐Ÿงฉ Core Features

  • Student face registration via webcam
  • Face recognition with real-time webcam feed
  • Attendance stored daily in CSV files
  • Trainable model (LBPH Face Recognizer)
  • No need for admin panel or database

๐Ÿ”ง Key Functionalities

1. register_student(request)

Allows students to register their ID and Name, and capture 20 face images using a webcam.

Highlights:

  • Faces detected using Haar Cascade
  • Manual image capture ('c' key)
  • Saves data to StudentDetails.csv

2. train_model(request)

Trains the model using the LBPH (Local Binary Pattern Histogram) algorithm from OpenCV.

Highlights:

  • Reads all images from TrainingImage/
  • Converts to grayscale using Pillow
  • Detects faces and associates with ID
  • Saves model as trained_model.yml

3. take_attendance(request)

Real-time face recognition and attendance marking.

Highlights:

  • Loads trained model and student data
  • Detects faces, predicts ID, fetches Name
  • Avoids duplicate entries per session
  • Saves daily CSV in Attendance/

CSV Format:

pgsqlCopy codeID, Name, Date, Time

4. view_attendance(request)

Displays attendance for the current date on a simple HTML page.

Highlights:

  • Reads CSV for todayโ€™s date
  • Renders a table in attendance.html
  • Shows empty state if no attendance file exists

๐Ÿ“‚ File Structure Snapshot

pgsqlCopy codemedia/
โ”œโ”€โ”€ TrainingImage/
โ”œโ”€โ”€ Attendance/
โ”‚   โ””โ”€โ”€ Attendance_YYYY-MM-DD.csv
โ””โ”€โ”€ StudentDetails.csv

recognition/
โ”œโ”€โ”€ views.py
โ”œโ”€โ”€ trained_model.yml
โ”œโ”€โ”€ haarcascade_frontalface_default.xml

templates/
โ”œโ”€โ”€ index.html
โ”œโ”€โ”€ register.html
โ””โ”€โ”€ attendance.html

๐Ÿš€ Usage Flow

  1. Navigate to /register/ and register student face
  2. Go to /train/ and train the face recognition model
  3. Use /take_attendance/ to mark attendance
  4. Check /view_attendance/ to see todayโ€™s attendance

image-23-1024x425 Face Recognition Attendance System with Python Django
Face Recognition Attendance System with Python Django
image-25-1024x370 Face Recognition Attendance System with Python Django
Face Recognition Attendance System with Python Django
image-24-1024x254 Face Recognition Attendance System with Python Django
Face Recognition Attendance System with Python Django

๐Ÿ“ Thoughts

This lightweight system is great for small-scale projects and educational purposes only. You can extend it by:

  • Adding email notifications after attendance
  • Integrating student login system
  • Visualizing attendance stats

ย 

Share this content: