Skip to content

In-a-loop/Smart_Attendance_Using_FAce_Recognition

Repository files navigation

This is my final year project .

Project Overview

This project is a Face Recognition and Attendance System that uses dlib and OpenCV for face detection and recognition. It includes a Graphical User Interface (GUI) for ease of use, allowing users to:

  • Capturing face images for students.
  • Generating face embeddings for recognition.
  • Training a face recognition model using the LBPH (Local Binary Patterns Histograms) algorithm.
  • Marking attendance in a database based on recognized faces.

Features

  • Face Detection: Detects faces using dlib's frontal face detector.
  • Face Embeddings: Generates 128-dimensional embeddings for each face using dlib's face recognition model.
  • Model Training: Trains the model for face recognition.
  • Attendance Management: Marks attendance in a database and updates student points based on check-in time.
  • Database Integration: Uses a MySQL database to store student details, attendance records, and points.
  • Graphical User Interface: Provides an easy-to-use GUI for all functionalities.

Prerequisites

  • Python: Version 3.7 or higher.
  • Libraries:
    • dlib
    • opencv-python
    • numpy
    • pickle
    • tkinter (for GUI)
    • mysql-connector-python
  • Database: MySQL server with the following schema:
    bash:
      CREATE TABLE IF NOT EXISTS students (
      id INT AUTO_INCREMENT PRIMARY KEY,
      roll_number VARCHAR(20) NOT NULL UNIQUE,
      name VARCHAR(100) NOT NULL,
      department VARCHAR(50),
      course VARCHAR(50),
      semester VARCHAR(20),
      points INT DEFAULT 0
       );
    
      CREATE TABLE IF NOT EXISTS student_images (
      id INT AUTO_INCREMENT PRIMARY KEY,
      student_id INT NOT NULL,
      image_path VARCHAR(255),
      FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE
      );
    
      CREATE TABLE IF NOT EXISTS attendance (
      id INT AUTO_INCREMENT PRIMARY KEY,
      student_id INT NOT NULL,
      date DATE NOT NULL,
      time TIME NOT NULL,
      FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE
      );
    

    Project Structure

env test/
│
├── capture_faces.py       # Script to capture face images for students
├── train_model.py         # Script to generate embeddings and train the model
├── recognize_face.py      # Script to recognize faces and mark attendance
├── gui.py                 # GUI for interacting with the system
├── db_connection.py       # Database connection utility
├── embeddings.pkl         # File to store face embeddings and labels
├── trained_model.yml      # Trained LBPH model for face recognition
├── dataset/               # Directory to store student face images
│   ├── <roll_number>/     # Subdirectory for each student
│   │   ├── image1.jpg
│   │   ├── image2.jpg
│   │   └── ...

How to Use

  1. Setup the Environment
    • Install the required Python libraries:
    •   bash:
        pip install dlib opencv-python numpy mysql-connector-python
      
    • Set up the MySQL database using the schema provided above.
  2. Run the GUI
    • Launch the GUI by running the gui.py script:
    •   bash:
             python gui.py
      
    • Use the GUI to:
      • Capture face images for students.
      • Train the face recognition model.
      • Recognize faces and mark attendance.
  3. Manual Execution (Optional)
    • If you prefer to run the scripts manually:
      • Capture Face Images

        • Run the capture_faces.py script to capture face images for a student:
        • bash:  
          python capture_faces.py
          
        • Follow the on-screen instructions to capture 150 images for each student.
      • Generate Embeddings

        • Run the train_model.py script to generate embeddings for the captured images:
        • bash:
          python train_model.py
          
        • This will create or update the embeddings.pkl file.
      • Train the Model

        • The train_model.py script also trains the LBPH face recognizer and saves the model as trained_model.yml.
      • Recognize Faces and Mark Attendance

        • Run the recognize_face.py script to start face recognition and mark attendance:
        •  bash:
             python recognize_face.py
          
        • The script will:
          • Recognize faces in real-time using the webcam.
          • Mark attendance in the database.
          • Award points based on check-in time.

GUI Features

  • The GUI provides the following functionalities:
    1. Capture Images:
      • Allows users to capture face images for a student by entering the roll number.
    2. Train Model:
      • Trains the face recognition model using the captured images.
    3. Recognize Faces:
      • Starts the face recognition process and marks attendance in the database.

Notes

  • Ensure that the shape_predictor_68_face_landmarks.dat and dlib_face_recognition_resnet_model_v1.dat files are in the project directory. These files are required for dlib's face detection and recognition.
  • The embeddings.pkl file stores face embeddings and labels. Do not delete this file unless you want to regenerate embeddings.

Future Improvements

  • Add email notifications for attendance.
  • Implement real-time analytics for attendance tracking.
  • Optimize the face recognition process for faster performance.

About

This is my final year project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors