Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Face Recognition GUI

Python OpenCV Dlib Tkinter

A desktop application for face recognition on photos and real-time webcam using Dlib and OpenCV, with an intuitive graphical interface for data collection, model training, and recognition.

Features

  • Dual Recognition Modes:
    • Photo Recognition: Upload and recognize faces in images
    • Real-time Webcam: Live face recognition from webcam feed
  • Integrated Data Collection: Collect training data through the GUI
  • Model Training: Train and save recognition models with one click
  • Haar Cascade Detection: Pre-trained frontal face detector
  • GUI Workflow: Step-by-step guided interface for the entire pipeline
  • Visual Results: Bounding boxes and labels on detected/recognized faces

Architecture

+------------------------------------------+
|         GUI Layer (Tkinter)              |
|  +-----------+ +---------------+          |
|  | Get Data  | | Train Model   |          |
|  | Recognize | | Webcam Feed   |          |
|  +-----------+ +---------------+          |
+------------------------------------------+
|       Face Detection (OpenCV)            |
|  - Haar Cascade (haarcascade_frontal     |
|    face_default.xml)                     |
|  - Multi-scale detection                 |
+------------------------------------------+
|    Face Recognition (Dlib + ML)          |
|  - Facial landmark detection             |
|  - Feature encoding (128-dim vector)     |
|  - Distance-based matching               |
+------------------------------------------+
|       Storage                            |
|  - dataset/ (collected face images)      |
|  - Models/ (trained model files)         |
+------------------------------------------+

Tech Stack

Category Technology
Language Python 3.8+
Face Detection OpenCV (Haar Cascade)
Face Recognition Dlib
ML scikit-learn
GUI Tkinter
Image Processing OpenCV, NumPy
Notebook Jupyter

Face Recognition Pipeline

Step 1: Face Detection

Uses OpenCV's pre-trained Haar Cascade classifier to detect frontal faces:

Input Image -> Grayscale -> Haar Cascade Detection -> Bounding Boxes -> Crop Faces
Parameter Value Description
scaleFactor 1.1 Image scale reduction at each level
minNeighbors 5 Detections needed to retain a rectangle
minSize (30, 30) Minimum possible face size

Step 2: Feature Extraction

Dlib extracts a 128-dimensional embedding vector for each detected face:

  • Face is aligned using 68-point facial landmarks
  • Normalized to a standard size and orientation
  • Passed through a deep neural network to produce a 128-D encoding
  • Faces of the same person produce similar encodings (small Euclidean distance)

Step 3: Recognition

Matching is performed by computing the Euclidean distance between face encodings:

distance = || encoding_1 - encoding_2 ||_2
Distance Result Interpretation
< 0.4 Match Same person (high confidence)
0.4 - 0.6 Possible Match Same person (medium confidence)
> 0.6 No Match Different person

Step 4: Data Collection Workflow

Start -> Click "Get Data" -> Webcam activates -> Faces detected ->
Images saved to dataset/ -> Enough samples collected -> Click "Train Model" ->
Model saved to Models/ -> Ready for recognition

Pre-trained Models

Model File Purpose
Haar Cascade haarcascade_frontalface_default.xml Frontal face detection
Dlib Face Recognition Models/ 128-D face encoding model

Getting Started

Prerequisites

  • Python 3.8 or higher
  • Webcam (for real-time recognition)

Installation

git clone https://github.com/nntrivi2001/Face-recognition-GUI.git
cd Face-recognition-GUI
pip install opencv-python numpy dlib scikit-learn imutils

Usage

  1. Run the application:

    jupyter notebook "Face Recognition/FaceRecognition.ipynb"
  2. Collect Training Data:

    • Click the "Get Data" button
    • Stand in front of the webcam
    • Multiple face images will be captured and saved to dataset/
  3. Train the Model:

    • Click "Train Model" or "Train and recognize"
    • The model processes all images in dataset/
    • Trained model is saved to Models/
  4. Recognize Faces:

    • Photo Mode: Choose a picture for recognition
    • Webcam Mode: Enable real-time webcam recognition

Project Structure

Face-recognition-GUI/
|-- Face Recognition/
|   |-- FaceRecognition.ipynb   # Main application with GUI
|-- Models/                     # Trained model files
|-- haarcascade_frontalface_default.xml   # Pre-trained Haar Cascade
|-- dataset/                    # Collected face images
|-- image.png                   # Screenshot 1
|-- image-1.png                 # Screenshot 2
|-- .gitignore
|-- .gitattributes
|-- README.md

Screenshots

Data Collection

Recognition Result

About

Face Recognition on a Photo and in Realtime Webcam

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages