This project implements a face recognition system for attendance tracking using Python, OpenCV, TensorFlow, and scikit-learn.
-
Clone the repository:
git clone https://github.com/yourusername/face-recognition-attendance-system.git cd face-recognition-attendance-system -
Create a virtual environment:
python -m venv venv # On Linux or MacOS: source venv/bin/activate # On Windows, use: venv\Scripts\activate -
Install required packages:
pip install -r requirements.txt
Run the main script:
First, run the following command to generate a key and input a password:
python3 generate_key.pyThen, start the Streamlit application:
streamlit run main.pyThis Face Recognition Attendance System uses a combination of traditional computer vision techniques and machine learning algorithms to detect and recognize faces. Here's a brief overview of the key components and their purposes:
-
Face Detection:
- Algorithm: Haar Cascade Classifier
- Purpose: Rapidly detect faces in input images or video streams
- Benefits: Fast, efficient, and works well for frontal faces
-
Feature Extraction:
- Algorithms: SIFT (Scale-Invariant Feature Transform) and MobileNetV2
- Purpose: Extract distinctive features from detected faces
- Benefits:
- SIFT: Robust to scale, rotation, and illumination changes
- MobileNetV2: Provides deep learning-based features, capturing high-level facial characteristics
-
Face Recognition:
- Algorithm: Support Vector Machine (SVM)
- Purpose: Classify extracted features to identify individuals
- Benefits: Effective for multi-class classification, works well with high-dimensional data
-
Data Preprocessing:
- Techniques: Grayscale conversion, histogram equalization
- Purpose: Enhance image quality and normalize input data
- Benefits: Improves feature extraction and recognition accuracy
-
Database Management:
- Technology: SQLite
- Purpose: Store user information and training session statistics
- Benefits: Lightweight, serverless, easy to integrate with Python
The system's performance can vary depending on the quality and quantity of training data. Typically, you can expect:
- Face Detection Accuracy: ~95-99% (under good lighting conditions)
- Face Recognition Accuracy: ~85-95% (with a well-trained model)
- Processing Speed: 5-10 frames per second (on average hardware)
To view detailed statistics for your trained model, check the output after the training process or query the training_sessions table in the SQLite database.
- Implement more advanced face detection algorithms (e.g., MTCNN or RetinaFace)
- Explore deep learning-based face recognition models (e.g., FaceNet or DeepFace)
- Add real-time attendance logging and reporting features
- Implement data augmentation techniques to improve model robustness
- Algorithm: Haar Cascade Classifier
- Implementation: OpenCV's
cv2.CascadeClassifier - Model:
haarcascade_frontalface_default.xml - Performance: Fast but may struggle with non-frontal faces or poor lighting conditions
- Future Improvement: Consider using MTCNN or RetinaFace for more robust face detection
- Deep Learning Model: MobileNetV2
- Framework: TensorFlow / Keras
- Input Shape: 224x224x3 (RGB image)
- Output: 1280-dimensional feature vector
- Pre-training: ImageNet weights
- Usage: Transfer learning, using the model as a feature extractor
- Advantages: Lightweight, efficient, and provides rich feature representations
- Algorithm: Support Vector Machine (SVM)
- Implementation: scikit-learn's
SVC(Support Vector Classification) - Kernel: RBF (Radial Basis Function)
- Probability Estimates: Enabled for confidence scoring
- Training: Performed on the combined features from MobileNetV2
- Color Conversion: BGR to RGB for MobileNetV2 input
- Resizing: Images resized to 224x224 for consistency
- Normalization: Pixel values scaled to [-1, 1] range for MobileNetV2
- Accuracy: Overall correct predictions / total predictions
- Precision: True positives / (true positives + false positives)
- Recall: True positives / (true positives + false negatives)
- F1 Score: Harmonic mean of precision and recall
- Confusion Matrix: Detailed breakdown of predictions per class
- Database: SQLite3
- Tables:
users: Stores user informationtraining_sessions: Records details of each training sessionrecognition_sessions: Logs performance metrics for recognition sessions
- Frame Skipping: Processing every 3rd frame during real-time recognition
- Confidence Thresholding: Recognitions below 50% confidence are labeled as "Unknown"
- Histogram Equalization: Applied to improve contrast in face images
- Python: 3.7+
- Key Libraries:
- OpenCV 4.5+
- TensorFlow 2.5+
- scikit-learn 0.24+
- NumPy 1.19+
This Face Recognition Attendance System combines traditional computer vision techniques with modern deep learning approaches to create an efficient and accurate solution. The use of transfer learning with MobileNetV2 allows for rich feature extraction without the need for extensive training data, while the SVM classifier provides a robust and interpretable classification mechanism. The system is designed to be scalable and can be further optimized for specific deployment scenarios.