Skip to content

This program enables real-time face recognition for attendance marking. It uses a webcam or video input to detect and recognize faces in real-time. When a recognized face is identified with sufficient accuracy, the corresponding name is recorded in an attendance file named Attendance.csv, along with the timestamp of the recognition.

ItsNotRohit02/Attendance-System-using-Facial-Recognition

Repository files navigation

Attendance using Facial Recognition

This program enables real-time face recognition for attendance marking. It uses a webcam or video input to detect and recognize faces in real-time. When a recognized face is identified with sufficient accuracy, the corresponding name is recorded in an attendance file named Attendance.csv, along with the timestamp of the recognition.

This repository contains six Python scripts for performing data augmentation on images and implementing face recognition using the face_recognition library and the streamlit framework in python.

Note

Create Folders Temp_Images, Original_Images and Augmented_Images. Add pictures of different faces in Temp_Images with the file names of the format Nameofperson<space>Number.jpg For example Rohit 1.jpg, Rohit 2.jpg, etc.

DataAugmentor.py

The DataAugmentor.py script provides a function called augment_image that performs data augmentation on an input image. The function takes an image as input and generates augmented versions of the image using various transformations. The transformations applied are:

  • Rotation: The image is rotated by 90 degrees clockwise and counterclockwise, resulting in two rotated images.
  • Mirroring: The image is horizontally flipped, creating a mirrored version of the image.
  • Contrast, Brightness, and Saturation Adjustment: Multiple combinations of contrast, brightness, and saturation factors are applied to the image. These factors control the intensity and color properties of the image.
  • The augmented images are stored in a list and returned by the augment_image function. The script also contains a main section where it reads input images from a specified directory (Original_Images). For each image, it calls the augment_image function to generate augmented versions of the image. The augmented images are saved in an output directory (Augmented_Images) with filenames that include the original image's basename and an index.

ImagePreprocessing.py

The ImagePreprocessing.py script is responsible for preprocessing images before performing face recognition. It reads input images from a specified folder (Temp_Images). For each image, the script performs the following steps:

  • Cropping: The image is cropped to a square shape by selecting a region of interest (ROI) based on the smaller dimension (height or width) of the image.
  • Resizing: The cropped image is resized to a fixed size of 512x512 pixels using the cv2.resize function.
  • Saving: The preprocessed image is saved in an output folder (Original_Images) with the same filename as the original image. The script ensures that the output folder exists before starting the image preprocessing.

FaceEncoder.py

The FaceEncoder.py script is responsible for encoding faces in augmented images for face recognition. It reads augmented images from a specified folder (Augmented_Images). For each image, the script performs the following steps:

  • Extracting Face Encodings: The script uses the face_recognition library to detect faces in the image and extract face encodings. Face encoding is a numerical representation of the face's features.
  • Storing Face Encodings: The extracted face encodings are stored in a dictionary called known_face_encodings. The dictionary maps a person's name to a list of their face encodings. If the person's name already exists in the dictionary, the face encodings are appended to the existing list. Otherwise, a new entry is created in the dictionary.
  • Saving Face Encodings to CSV: After processing all the images, the script writes the face encodings and corresponding names to a CSV file named EncodedFaces.csv. Each row in the CSV file contains a comma-separated list of face encodings and the corresponding person's name. The script ensures that the output CSV file is created or overwritten before starting the face encoding process.

FaceRecognizer.py

The FaceRecognizer.py script performs real-time face recognition using a webcam. It loads the face encodings and names from the CSV file generated by the FaceEncoder.py script. The script continuously captures frames from the webcam and performs the following steps:

  • Face Detection: The script uses the face_recognition library to detect faces in the captured frame.
  • Face Recognition: For each detected face, the script compares the face's encoding with the known face encodings loaded from the CSV file. It calculates the similarity (distance) between the face encodings and finds the best match.
  • Attendance Recording: If the best match has a similarity score above a threshold (50 in this case), the person's name is considered recognized. The person's name, along with the current timestamp, is recorded in an attendance CSV file named Attendance.csv. The attendance file is opened in "append" mode, and a new row is written if the person's name is not already present in the file.
  • Displaying Results: The script overlays rectangles and text on the video frame to indicate the detected faces and their recognized names. The video feed is displayed in a window.
  • Exiting the Program: The script continuously loops until the 'q' key is pressed. When the 'q' key is detected, the script releases the video capture resources and closes the windows.

Image.py

The pages\1_Image.py script allows you to upload an image and recognize faces within it.

  • The script loads face encodings and corresponding names from a CSV file (EncodedFaces.csv).
  • You can upload an image (in JPG, JPEG, or PNG format) using the provided file uploader.
  • Once the image is uploaded, the script uses face_recognition to locate faces in the image and compare them with the loaded face encodings.
  • Recognized faces are labeled with their corresponding names, and bounding boxes are drawn around the faces.
  • The processed image with labeled faces is displayed along with the recognized names.
  • If a recognized name is not "Unknown," it is considered attendance, and the name is displayed as marked attendance.

Video.py

The pages\2_Video.py script allows you to upload a video and perform real-time face recognition.

  • The script loads face encodings and corresponding names from a CSV file (EncodedFaces.csv).
  • You can upload a video (in MP4 format) using the provided file uploader.
  • Once the video is uploaded, the script opens it and continuously processes each frame.
  • For each frame, the script uses face_recognition to locate faces and compare them with the loaded face encodings.
  • Recognized faces are labeled with their corresponding names, and bounding boxes are drawn around the faces.
  • The processed video is displayed in real-time with the recognized names overlaid on each frame.
  • If a recognized name is not "Unknown" and has not been previously recognized, it is considered attendance, and the name is displayed as marked attendance.

About

This program enables real-time face recognition for attendance marking. It uses a webcam or video input to detect and recognize faces in real-time. When a recognized face is identified with sufficient accuracy, the corresponding name is recorded in an attendance file named Attendance.csv, along with the timestamp of the recognition.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages