turhancan97 / Intelligent-Face-Recognition-Attendance-System

This project is a comprehensive face recognition-based attendance system for universities. It leverages OpenCV for face detection and recognition, Firebase for data storage, and Flask for the web interface. The system allows for student registration, face capture, and attendance tracking, providing a modern solution for attendance management.
MIT License
29 stars 15 forks source link
attandance deepface face-recognition flask-application machine-learning web-application

Face Recognition Attendance System

soft

This project is a comprehensive attendance system that leverages the power of face recognition to identify individuals and mark their attendance. Built with Python, Flask, OpenCV, and Firebase, the system provides an efficient and automated solution to track attendance in various settings such as universities or workplaces.

The system allows users to upload their image to the database, which is then used to recognize their face during attendance checks. The recognized faces are matched with the database, and the attendance is updated in real-time. The system also includes a secure login feature for teachers to view the attendance records.

This project is an excellent example of how computer vision and machine learning can be used to automate traditional processes, making them more efficient and accurate.

Table of Contents

Introduction

In traditional attendance systems, the process of marking attendance is often manual, time-consuming, and prone to errors. With the advent of machine learning and computer vision, we now have the tools to automate this process and make it more efficient and accurate.

Our Face Recognition Attendance System is designed to leverage these technologies to provide a seamless and automated attendance tracking solution. The system uses face recognition technology to identify individuals and mark their attendance. This process eliminates the need for manual entry and reduces the chances of errors or fraudulent entries.

The system is built using Python, Flask, OpenCV, and Firebase. Python and Flask provide the backend functionality, OpenCV is used for face detection and recognition, and Firebase is used as the database to store user information and attendance records.

The system also includes a secure login feature for teachers, allowing them to view the attendance records. This feature ensures that only authorized individuals have access to the attendance data.

Whether you're a university looking to streamline your attendance tracking process or a business looking to automate your employee check-in system, our Face Recognition Attendance System provides a robust and efficient solution.

Project Demo

Please Click The Picture Below For the Project Video

drawing

Features

The Face Recognition Attendance System comes with a host of features designed to make attendance tracking as seamless and efficient as possible:

  1. Face Recognition: The system uses advanced face recognition technology to identify individuals and mark their attendance. This eliminates the need for manual entry and ensures accuracy in attendance tracking.

  2. Real-Time Attendance Tracking: The system tracks attendance in real-time. As soon as an individual is recognized by the system, their attendance is marked and updated in the database.

  3. Secure Teacher Login: The system includes a secure login feature for teachers. This allows teachers to view the attendance records and ensures that only authorized individuals have access to this data.

  4. Multi-Class Support: The system supports multiple classes. Students can be enrolled in multiple classes, and their attendance is tracked separately for each class.

  5. Database Integration: The system is integrated with Firebase, a cloud-based NoSQL database. This allows for efficient storage and retrieval of user information and attendance records.

  6. Webcam Support: The system supports webcam input for face recognition. This makes it easy to set up and use in a variety of settings.

  7. User-Friendly Interface: The system features a user-friendly interface, making it easy for users to navigate and use the system.

  8. Open Source: The system is open source. Developers are welcome to contribute and help improve the system.

Screenshots

drawing
Home Page of the Interface
drawing
Page to add student's information to the database (After capture image/upload image)
drawing
Page after Teacher Login (Attendance list)
drawing
Page after attending the class
drawing
Choosing a Class to Attend

Installation

To get the Face Recognition Attendance System up and running on your local machine, follow these steps:

  1. Clone the Repository: First, clone the repository to your local machine. You can do this by running the following command in your terminal:

    git clone https://github.com/turhancan97/Intelligent-Face-Recognition-Attendance-System.git
  2. Create a virtual environment and activate it. You can do this by running the following commands in your terminal:

    python environment

    python3.8 -m venv your_env_name
    source your_env_name/bin/activate

    or

    conda environment

    conda create -n your_env_name python=3.8
    conda activate your_env_name

This will create a virtual environment and activate it. All the dependencies will be installed in this virtual environment.

  1. Install Dependencies: Navigate into the cloned project directory and install the necessary dependencies by running:

    pip install -r requirements.txt

    This command will install all the necessary libraries and packages listed in the requirements.txt file.

    Please note that you need to download the shape predictor file 'shape_predictor_68_face_landmarks.dat' from the dlib website. You can download the file from here. You can put the file in the detection folder and you need to write full path of the file in the face_matching.py file for the datFile variable as below.

    datfile

  2. Set Up Firebase: The system uses Firebase for database operations. You need to set up a Firebase project and replace the Firebase configuration in the project with your own. You can follow the Firebase setup guide for instructions.

    1. First you need to create a project in Firebase. Firebase Project
    2. Later, you need to create Realtime Database (Start in test mode). Firebase Realtime Database
    3. Copy your database URL and paste it to the configs/database.yaml file into enter-your-databaseURL section. Example: https://abcd-6ccf7-default-rtdb.firebaseio.com/
    4. Now, start storage in test mode.
    5. Copy the folder path without 'gs://' part and paste it to.the configs/database.yaml file into enter-your-storageBucket section. Example: abcd-6ccf7.appspot.com
    6. Finally you need to create a service account key as json file. You can do it via project settings on Firebase project. Then copy the path of the json file and paste it to the configs/database.yaml file into enter-your-serviceAccountKey-path section. Example: /home/your_user_name/Downloads/serviceAccountKey.json Firebase Service Account Key
  3. Run the Application: First run the command below and enter a password for teacher login.

    python generate_password_hash.py

Then copy the has to the configs/database.yaml file into enter-your-teacher-login-hash section.

Once all the setup is complete, you can run the application by executing the following command in the terminal:

   python app.py

This will start the Flask server and the application will be accessible at http://127.0.0.1:5000/.

Please note that you need a webcam connected to your machine for the face recognition feature to work. If you are using a laptop, the built-in webcam will work fine.

Usage

Once you have the Face Recognition Attendance System running, you can start using it by following these steps:

  1. Home Page: Open your web browser and navigate to http://127.0.0.1:5000/. This will take you to the home page of the application.

  2. Upload a New Face: To add a new student to the system, click on the "Upload a new face as image" button. This will allow you to upload an image of the student's face. The image should be clear and the student's face should be visible. Also, you can capture the image from the camera by clicking on the "Capture a new face from camera" button.

  3. Add Student Information: After uploading the image, you will be redirected to a page where you can enter the student's information. This includes the student's name, email, user type (student or teacher), classes they are enrolled in, and a password. Once you have entered all the information, click on the "Submit" button.

  4. Face Recognition: Back on the home page, you can click on the "Recognize Face" button. This will start the face recognition process. The system will try to match the face in front of the webcam with the faces in the database.

  5. Class Selection: If a match is found, you will be redirected to a page where you can select the class. The attendance for the selected class will be updated in the database.

  6. Teacher Login: If you are a teacher, you can view the attendance by clicking on the "Teacher Login" button on the home page. You will be asked to enter a password. Once the correct password is entered, you will be redirected to the attendance page where you can see the list of students and their attendance.

Remember, the face recognition feature requires a webcam. If you are using a laptop, the built-in webcam will work fine. If you are using a desktop, you will need to connect a webcam to your machine.

Dependencies

The Face Recognition Attendance System relies on several Python libraries to function correctly. Here is a list of the main dependencies:

To install these dependencies, you can use pip, a package manager for Python. Simply run the following command in your terminal:

pip install -r requirements.txt

This will install all the required packages. Make sure you are in the correct directory when you run this command (the directory should contain the requirements.txt file).

Contribution

Contributions to the Face Recognition Attendance System are very welcome! If you have a feature request, bug report, or proposal for code refactoring, please feel free to open an issue or create a pull request.

Here are some ways you can contribute:

Before contributing, please make sure to check the existing issues and pull requests to avoid duplicating efforts. Also, when you open a pull request, make sure to include a clear and detailed description of the changes you have made.

Thank you for your interest in contributing to the Face Recognition Attendance System!

Future Improvements

There are several areas where the system could be improved or expanded in the future:

These are just a few ideas for future improvements. We are always open to new ideas and suggestions, so feel free to contribute!

License

This project is licensed under the MIT License. This means you are free to use, modify, and distribute the project under the terms of this license. Please see the LICENSE file for more details.

Please note that this project is provided "as is" without any warranty. The authors are not responsible for any damage or issues that may arise from using the project. Always check the code yourself before using it in a production environment.

Technical Information

System Architecture Design

Here's a high-level view of the system components and their interactions:

drawing
Diagram to visually represent the system architecture.

1. Face Recognition System: This is the core of your project. It will capture images or video frames, detect faces, extract features, and match faces. This system will be developed using Python and OpenCV.

2. User Interface: This is the part of the system that users (students and instructors) will interact with. It will display information from the Firebase database and send user inputs to the database. The interface will be developed as a web application using HTML, CSS, and JavaScript.

3. Firebase Database: This is where all the necessary data will be stored. The database will store student information, attendance records, and any other necessary data. The face recognition system and the user interface will both interact with the database to store and retrieve data.

Interactions:

This is a simplified view of the system architecture and the interactions between the components. Depending on the specific requirements of your project, you may need to add more components or interactions. For example, you might need to add a component for handling user authentication if you want to ensure that only registered students and instructors can access the system.docs/images/database_design.png

Database Design

Let's now design and draw the database schema for Firebase. This includes defining the data that will be stored (e.g., student information, attendance records, etc.) and how this data will be structured and related.

drawing
Database schema for Firebase
  1. Users Collection: This collection will store information about all users, including both students and instructors. Each user will have a unique ID, and the data stored for each user might include:

    • userID: A unique identifier for the user.
    • name: The user's full name.
    • email: The user's email address.
    • embeddings: user face embeddings
    • userType: The type of user (student or instructor).
    • password: The user's password (stored securely).
    • classes: List of programs in which the user is enrolled (for students) and the number of attendance of that student

This is a simplified view of the structure of our database. We also stored the images of the student in the Firebase Storage. The images are stored in a folder named static/images and name of the images are the student's ID.

Face Recognition System Development

This is a crucial part of your project and involves several steps:

drawing
Face Recognition System Flow
  1. Research Face Recognition Algorithms:

    • We start by researching various face recognition algorithms. There are many available, each with its own strengths and weaknesses. Some popular choices include Eigenfaces, Fisherfaces, Local Binary Patterns Histograms (LBPH), and deep learning-based methods.
    • We consider factors such as simplicity, accuracy, computational complexity, and robustness to variations in lighting, pose, and facial expression when choosing an algorithm.
  2. Implement Face Recognition System:

    • Once you've chosen an algorithm, the next step is to implement it using Python and OpenCV. This will involve several sub-steps:
      • Face Detection: Before you can recognize a face, you need to detect it. OpenCV provides pre-trained classifiers. We used the Haar Cascade Classifier for face detection.
      • Face Alignment: Faces in the input images might be tilted or turned, which can reduce the accuracy of your face recognition algorithm. To correct this, we use an alignment algorithm to align the detected faces. This typically involves rotating and scaling the face so that the eyes and mouth are in fixed positions.
      • Feature Extraction: This involves extracting features from the aligned faces that can be used to distinguish different individuals. We used DeepFace method to calculate the face embeddings with the help of FaceNet model.
      • Face Matching: This involves comparing the extracted features to a database of known faces and finding the best match. This basically involves calculating a distance or similarity measure between the feature vectors. The face in the database that has the smallest distance or highest similarity to the input face is considered the best match. Output the ID of the matched face (FACE_ID).
  3. Integrate Face Recognition System with Firebase Database:

    • Once your face recognition system is working, the next step is to integrate it with your Firebase database. This will involve several sub-steps:
      • When a face is detected and recognized, the system should send the student's ID and the current date and time to the Firebase Database to record the attendance.
      • The system should also be able to retrieve student information and face data from the Firebase Database for the face matching process.
      • The system should also be able to retrieve attendance records from the Firebase Database for display in the user interface.