Skip to content

About

Offline Python GUI for real-time webcam face recognition with FaceNet embeddings.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

Face Recognition GUI

Authors

What is this project?

Face Recognition GUI is a desktop application written in Python that performs real-time face recognition using your computer’s webcam. It allows you to capture and label faces (assign names to them) and later recognize those faces live in front of the camera — all through a simple, graphical interface built with Tkinter.

This educational project performs enrollment and recognition locally, without a cloud recognition service. Initial dependency installation and the first pretrained FaceNet initialization may require internet access to download weights; recognition can run offline after those weights are cached.

The system uses two deep learning models from the facenet-pytorch library:

  • MTCNN for detecting faces in each video frame.
  • InceptionResnetV1 (FaceNet) for converting faces into 512-dimensional numerical embeddings.

What This Demonstrates

  • Real-time webcam processing with OpenCV
  • Face detection with MTCNN and embedding extraction with FaceNet
  • Local enrollment and recognition without cloud APIs
  • A Tkinter GUI for labeling faces and running prediction mode

How It Works

The pipeline has three main stages: Face Detection → Face Embedding → Face Recognition.

1) Face Detection (MTCNN)

Each webcam frame is processed with MTCNN, which returns bounding boxes around one or more faces in the image.

2) Face Embedding (FaceNet / InceptionResnetV1)

Each detected face is cropped and resized to 160×160, then fed into FaceNet, producing a 512-dimensional embedding (a numeric vector that represents the face). The embedding distances are used to compare enrolled faces with incoming images. Recognition quality depends on image conditions, enrollment data, and the selected threshold.

3) Local Database and Recognition

When you label faces, each image is saved locally under:

face_data/<person_name>/

The app computes embeddings for all stored images and keeps them in memory. During recognition, a new face’s embedding is compared to all stored embeddings using Euclidean distance. The smallest distance is taken as the match; if it’s smaller than a configurable threshold (default 1.0), the system labels that face as known; otherwise it shows “Unknown.”


How to Use It

Install & Run

git clone https://github.com/RezaDadbin/Real-time-Face-recognition.git
cd Real-time-Face-recognition
python -m venv .venv
source .venv/bin/activate      # macOS/Linux
# or
.venv\Scripts\activate       # Windows
pip install -r requirements.txt
python -m src.face_rec_gui.app

Label Faces

  1. In the main window, click “Labeling UI.”
  2. Enter a person’s name.
  3. The webcam opens:
    • Press s to save the current frame to face_data/<name>/.
    • Press q to quit labeling mode.
  4. After quitting, embeddings are computed for all saved images.

Recognize Faces

  1. From the main window, click “Prediction UI.”
  2. The webcam starts and detects faces live.
  3. Each face is embedded and compared to known ones.
  4. If the smallest distance is below the threshold, the name appears on the bounding box; otherwise it shows Unknown.
  5. Press q to exit.

Configure (configs/default.yaml)

device: "cpu"                # or "cuda" for GPU
database_path: "face_data"
recognition_threshold: 1.0   # smaller = stricter; larger = more lenient
camera_index: 0              # change if you have multiple webcams

Technical Overview

Component Purpose
Tkinter Graphical user interface
OpenCV Webcam frames & drawing
MTCNN Face detection
FaceNet (InceptionResnetV1) 512-D face embeddings
NumPy Vector math & distances
PyTorch Deep model execution
YAML Config management

Recognition decision: for a new embedding e_new, compute distances d_i = ||e_new - e_stored,i||_2. Let d_min = min_i d_i. If d_min < threshold, assign the corresponding label; else Unknown.


Tests

With the dependencies installed, run the existing tests from the repository root:

python -m pytest -q

CI uses the same invocation so the repository root is available for the src.face_rec_gui import.

Data Privacy

Enrolled images are stored locally in face_data/ and processed locally by the application. Pretrained FaceNet weights may be downloaded on first initialization and cached by facenet-pytorch. This project does not establish a validated biometric-security or privacy guarantee.


About

Offline Python GUI for real-time webcam face recognition with FaceNet embeddings.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages