A highly efficient and accurate real-time face attendance system using OpenCV and LBPH Face Recognition. Features both a desktop GUI application and a REST API for seamless attendance tracking.
- Introduction
- Features
- Architecture
- Demo
- Technologies Used
- Project Structure
- Installation
- Usage
- API Documentation
- Deployment
- Contributing
- License
- Contact
Attendance management is a critical component in educational institutions and organizations. This Real-time Face Attendance system provides an automated solution to streamline the attendance process using facial recognition technology. The system ensures accuracy, reduces manual effort, and enhances security by preventing proxy attendance.
Instantly recognize and record attendance as individuals enter the monitored area using live camera feeds.
- Desktop Application: Full-featured Tkinter GUI for local use
- REST API: Flask-based API for web integration
Capable of handling multiple users simultaneously, ideal for classrooms or auditoriums.
Intuitive dark-themed dashboard with four main tabs: Register, Train, Attendance, and Database.
Generates daily attendance CSV reports with timestamps for analysis and record-keeping.
- Image Capture: Uses webcam to capture live video streams
- Face Detection: Haar Cascade classifier detects faces in real-time
- Face Recognition: LBPH (Local Binary Patterns Histograms) algorithm identifies individuals
- Attendance Logging: Records recognized faces with timestamps to CSV files
- User Interface: Displays real-time status and provides administrative controls
| Technology | Purpose |
|---|---|
| Python 3.8+ | Primary programming language |
| OpenCV | Real-time image/video processing |
| opencv-contrib-python | LBPH Face Recognizer |
| Tkinter | Desktop GUI framework |
| NumPy | Numerical operations |
| Pandas | CSV data handling |
| Pillow | Image processing for GUI |
| Technology | Purpose |
|---|---|
| Flask | Web framework |
| Flask-CORS | Cross-origin resource sharing |
| MediaPipe | Face detection |
| PyJWT | Authentication tokens |
| PyMySQL | MySQL database connector |
| Gunicorn | Production WSGI server |
realtime-face-attendance/
├── codes/
│ └── ultimate_system.py # Desktop Tkinter application (main)
├── deployment/
│ └── api.py # Flask REST API
├── model/
│ └── Haarcascade.xml # Face detection model
├── database/
│ └── init_db.sql # MySQL schema
├── docs/
│ └── PROJECT_DOCUMENTATION.md
├── TrainingImage/ # Captured face images (gitignored)
├── TrainingImageLabel/ # Trained model files (gitignored)
├── Attendance/ # CSV attendance records (gitignored)
├── logs/ # Application logs (gitignored)
├── .env.example # Environment variables template
├── .gitignore
├── requirements.txt
├── LICENSE.md
└── README.md
- Python 3.8 or higher
- Git
- Webcam for real-time video capture
- MySQL (optional, for API deployment)
-
Clone the Repository
git clone https://github.com/yxshee/realtime-face-attendance.git cd realtime-face-attendance -
Create a Virtual Environment
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies
pip install -r requirements.txt
-
Configure Environment (for API only)
cp .env.example .env # Edit .env with your database credentials
# Activate virtual environment
source venv/bin/activate
# Run the desktop application
python codes/ultimate_system.py- Register Tab: Enter student ID and name, then capture 60 face images
- Train Tab: Train the LBPH model with captured images
- Attendance Tab: Enter subject name and start real-time attendance tracking
- Database Tab: View today's attendance records
# Activate virtual environment
source venv/bin/activate
# Initialize database (MySQL required)
mysql -u root -p < database/init_db.sql
# Run the API server
python deployment/api.pyThe API runs on http://localhost:5001
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /api/login |
Authenticate user | No |
| POST | /api/register-face |
Register new face | Yes |
| POST | /api/attendance |
Mark attendance | Yes |
All protected endpoints require a JWT token in the Authorization header:
Authorization: Bearer <your-token>
curl -X POST http://localhost:5001/api/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "password"}'This project has two deployment modes:
| Mode | Platform Recommendation | Use Case |
|---|---|---|
| Desktop App | Local machine | Classroom/office use |
| REST API | Railway, Render, Heroku | Web integration |
Netlify is designed for static sites and serverless functions. This project requires:
- Continuous camera access (desktop only)
- Persistent server processes
- Real-time face recognition (exceeds serverless time limits)
- Push code to GitHub
- Connect repository to Railway or Render
- Set environment variables from
.env.example - Deploy with start command:
gunicorn deployment.api:app
web: gunicorn deployment.api:app --bind 0.0.0.0:$PORT
| Variable | Description | Default |
|---|---|---|
SECRET_KEY |
Flask secret key | Required |
DB_HOST |
MySQL host | localhost |
DB_USER |
MySQL username | root |
DB_PASSWORD |
MySQL password | Required |
DB_NAME |
Database name | face_attendance |
Contributions are welcome! Please see our Contributing Guidelines.
- Fork the repository
- Create a feature branch:
git checkout -b feature/YourFeature - Commit changes:
git commit -m "Add YourFeature" - Push to branch:
git push origin feature/YourFeature - Open a Pull Request
This project is licensed under the MIT License.
- Author: Yash Dogra
- Email: yxshdogra@gmail.com
- OpenCV - Computer vision tools
- MediaPipe - Face detection
- Python Community - Excellent libraries and documentation
