An AI-powered, real-time face recognition-based gate access system designed to automate entry and exit management using computer vision.
This project enhances security and attendance tracking by combining Python, OpenCV, and MySQL for efficient facial identification and data logging.
Developed by Aakash Kumar Jha.
- Real-time Face Recognition: Detects and identifies registered faces through a live camera feed.
- Automatic Entry & Exit Tracking: Maintains an accurate log of all individuals entering and exiting the premises.
- Database Integration (MySQL): Stores all user records and gate logs securely.
- Live Camera Feed: Displays the real-time recognition process with visual confirmation.
- Access Control: Automatically grants or denies entry based on recognition confidence.
- Comprehensive Logging: Every recognition event is time-stamped and saved for auditing.
- Modular Design: Easy to scale, customize, or integrate with IoT-based gate systems.
- Error Handling: Built-in safety checks for camera and database connections.
- Language: Python 3.10+
- Libraries: OpenCV, face_recognition, NumPy, Pandas
- Database: MySQL
- Framework (optional): Flask (for dashboard integration)
- Operating System: Windows 10/11 (tested)
- Python 3.10+
- MySQL Server
- Webcam or external camera
- Windows 10/11
Install required dependencies:
pip install -r requirements.txt-
Clone the Repository
git clone https://github.com/Aakash-2005/Face-Recognition-Gate-System.git cd Face-Recognition-Gate-System -
Install Dependencies
pip install -r requirements.txt
-
Set up MySQL Database
- Create a database named
face_gate_system - Configure database credentials in
config.py(if available)
- Create a database named
-
Run the Application
python main.py
- Launch
main.py - The system initializes the camera, loads stored face encodings, and connects to the database.
- The camera detects a face.
- The system compares it with the stored database encodings.
- If matched, the user is marked as “Authorized” and entry is logged.
- If not matched, the system displays “Unrecognized Face.”
Table: users
| Column | Type | Description |
|---|---|---|
| id | INT | Unique user ID |
| name | VARCHAR | Name of the individual |
| face_encoding | BLOB | Encoded face data |
| access_status | VARCHAR | Current access state |
Table: gate_logs
| Column | Type | Description |
|---|---|---|
| log_id | INT | Log entry ID |
| name | VARCHAR | Recognized name |
| time_stamp | DATETIME | Date and time of recognition |
| action | VARCHAR | Entry/Exit status |
- Live Video Feed: Displays real-time recognition camera view.
- Recognition Result Panel: Shows user name, recognition confidence, and gate status.
- Log Panel: Displays historical access data fetched from MySQL.
- Clean and modern interface using Tkinter (optional).
- Visual indicators for “Authorized” (green) and “Denied” (red).
- Automatic refresh for real-time updates.
- Detection: OpenCV captures frames from the camera.
- Encoding: face_recognition library extracts facial embeddings.
- Comparison: Embeddings compared with stored encodings.
- Decision: If confidence ≥ threshold (default 0.5), grant access.
All activities are logged both in the console and MySQL database, including:
- Successful recognitions
- Unknown face attempts
- System or camera errors
Edit config.py to modify:
- MySQL credentials
- Recognition threshold
- Camera index
- Logging level
- Integration with IoT-enabled gate motors
- Addition of liveness detection (anti-spoofing)
- Multi-camera support
- Cloud synchronization and dashboard analytics
- Notification system for unknown face attempts
Camera not working?
- Ensure no other app is using the webcam.
- Try changing the camera index in
main.py.
Database not connecting?
- Check MySQL service is running.
- Verify credentials in
config.py.
Face not recognized?
- Ensure proper lighting.
- Retrain and save clear face samples.
- Optimized frame processing for faster recognition.
- Efficient memory handling to prevent lags.
- Batch encoding for multiple users.
Aakash Kumar Jha Passionate about Artificial Intelligence, Computer Vision, and automation. Focused on developing practical AI-based solutions for real-world problems.
Open-source project for educational and research purposes. © 2025 Aakash Kumar Jha. All rights reserved.
Version: 2.0 Last Updated: November 2025