A real-time face recognition-based access control system built with Python and OpenCV. It uses Haar Cascade for face detection and an LBPH (Local Binary Patterns Histograms) recognizer to grant or deny access via live webcam feed — simulating a smart, face-based lock system.
🎓 Developed as a semester project — University of Agriculture, Faisalabad.
The system works in three stages:
- Face Capture — Collects and normalizes face images from a webcam to build a training dataset.
- Training — Trains an LBPH face recognizer on the captured dataset and saves the model.
- Recognition / Lock — Runs live recognition on webcam input, applies a confidence threshold and rolling-average smoothing, and displays a "SYSTEM LOCKED / UNLOCKED" style UI with ACCESS GRANTED / DENIED overlays.
- Real-time face detection using Haar Cascade Classifier
- Face capture with automatic + manual (SPACE key) image collection
- Lighting normalization via histogram equalization
- LBPH-based face recognition with configurable confidence threshold
- Rolling confidence averaging for stable, less jittery predictions
- Live visual feedback: bounding boxes, name labels, access status, confidence score
- Simple, dependency-light OpenCV implementation (no deep learning frameworks required)
- Python 3.11
- OpenCV (
opencv-contrib-python— required forcv2.facemodule) - NumPy
FaceLock-AccessControl/
├── face_capture.py # Captures & saves face images for training
├── train.py # Trains the LBPH recognizer on captured faces
├── face_lock.py # Runs real-time recognition & access control
├── requirements.txt
└── README.md
Note: The
dataset/folder (captured face images),trainer.yml(trained model), andlabels.pkl(label mapping) are not included in this repository for privacy reasons. These files are generated locally when you run the scripts yourself — see Usage below.
-
Clone the repository:
git clone https://github.com/<your-username>/FaceLock-AccessControl.git cd FaceLock-AccessControl
-
Create and activate a virtual environment:
python -m venv venv # Windows venv\Scripts\activate # macOS/Linux source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
Step 1 — Capture your face data
python face_capture.pyEnter your name when prompted, then look at the camera. Images are auto-captured and saved under dataset/<your-name>/.
Step 2 — Train the model
python train.pyThis generates trainer.yml (trained model) and labels.pkl (name-label mapping).
Step 3 — Run the Face Lock system
python face_lock.pyThe webcam feed opens, showing a live SYSTEM LOCKED / UNLOCKED overlay. Recognized faces (above the confidence threshold) show ACCESS GRANTED; unrecognized faces show ACCESS DENIED. Press q to quit.
This repository does not include any personal face images, the trained model, or label files. Only the source code is shared. Anyone using this project generates their own dataset and model locally by running the scripts above.
- Replace LBPH with a deep learning-based recognizer (e.g., FaceNet / dlib embeddings) for higher accuracy
- Add a GUI (Tkinter/PyQt) instead of raw OpenCV windows
- Log access attempts with timestamps
- Multi-user role-based access levels
Your Name University of Agriculture, Faisalabad — 5th Semester Project
This project is open-source and available for educational purposes.