Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FaceLock - Access Control

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.


🔍 Overview

The system works in three stages:

  1. Face Capture — Collects and normalizes face images from a webcam to build a training dataset.
  2. Training — Trains an LBPH face recognizer on the captured dataset and saves the model.
  3. 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.

✨ Features

  • 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)

🛠️ Tech Stack

  • Python 3.11
  • OpenCV (opencv-contrib-python — required for cv2.face module)
  • NumPy

📁 Project Structure

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), and labels.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.


⚙️ Installation

  1. Clone the repository:

    git clone https://github.com/<your-username>/FaceLock-AccessControl.git
    cd FaceLock-AccessControl
  2. Create and activate a virtual environment:

    python -m venv venv
    
    # Windows
    venv\Scripts\activate
    
    # macOS/Linux
    source venv/bin/activate
  3. Install dependencies:

    pip install -r requirements.txt

▶️ Usage

Step 1 — Capture your face data

python face_capture.py

Enter 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.py

This generates trainer.yml (trained model) and labels.pkl (name-label mapping).

Step 3 — Run the Face Lock system

python face_lock.py

The 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.


🔒 Privacy Note

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.


📌 Future Improvements

  • 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

👤 Author

Your Name University of Agriculture, Faisalabad — 5th Semester Project


📄 License

This project is open-source and available for educational purposes.

About

Real-time face recognition access control system built with Python & OpenCV (Haar Cascade + LBPH). Captures, trains, and authenticates faces via webcam to simulate a smart lock.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages