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.
- 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
+------------------------------------------+
| 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) |
+------------------------------------------+
| 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 |
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 |
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)
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 |
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
| Model | File | Purpose |
|---|---|---|
| Haar Cascade | haarcascade_frontalface_default.xml |
Frontal face detection |
| Dlib Face Recognition | Models/ |
128-D face encoding model |
- Python 3.8 or higher
- Webcam (for real-time recognition)
git clone https://github.com/nntrivi2001/Face-recognition-GUI.git
cd Face-recognition-GUI
pip install opencv-python numpy dlib scikit-learn imutils-
Run the application:
jupyter notebook "Face Recognition/FaceRecognition.ipynb" -
Collect Training Data:
- Click the "Get Data" button
- Stand in front of the webcam
- Multiple face images will be captured and saved to
dataset/
-
Train the Model:
- Click "Train Model" or "Train and recognize"
- The model processes all images in
dataset/ - Trained model is saved to
Models/
-
Recognize Faces:
- Photo Mode: Choose a picture for recognition
- Webcam Mode: Enable real-time webcam recognition
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

