Real-time face recognition using your webcam, built with OpenCV (Haar cascade
for detection + LBPH for recognition). No dlib/CMake build required — this
stack installs cleanly on Windows via pip.
No Python needed — just double-click, in this order:
CaptureFaces.exe— pops up a name box, then opens the webcam to capture face samples for that person.TrainModel.exe— retrains on everyone captured so far, shows a "done" popup.Recognize.exe— live webcam recognition window. Green box + name = match, red box + "Unknown" = no confident match.ManagePeople.exe— table of everyone enrolled (photo, name, registration date, sample count). Select a row and click Delete Selected to remove someone; it deletes their photos and automatically retrains the model so they stop being recognized.
These are self-contained builds (produced with PyInstaller from the .py
files below) — rebuild them if you edit the source, see "Rebuilding the
exes" below.
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt-
Capture samples for each person you want to recognize (repeat per person):
python capture_faces.py "Alice" --samples 30This opens your webcam and saves cropped face images to
dataset/Alice/. Move your head slightly during capture for better coverage. -
Train the model on everyone captured so far:
python train_model.py
Produces
trainer.yml(the model) andlabels.pickle(id -> name map). -
Run live recognition:
python recognize.py
Opens your webcam, draws a box around each detected face, and labels it with the closest known match (green) or "Unknown" (red) if the match isn't confident enough. Press
qto quit.Tune matching strictness with
--confidence-threshold(LBPH reports a distance — lower is a better match; default70, lower it for stricter matching, raise it if known people are getting labeled "Unknown"). -
Remove someone:
python manage_people.py
Opens the same table/delete GUI as
ManagePeople.exe.
- Add: run
capture_faces.py(orCaptureFaces.exe) with a new name, then retrain. - Remove: run
manage_people.py(orManagePeople.exe) and delete their row — retraining happens automatically.
Either way, no exe rebuild is required — trainer.yml/labels.pickle live
next to the exes and are read fresh each run.
Only needed after editing the .py source:
.venv\Scripts\python.exe -m pip install pyinstaller
.venv\Scripts\python.exe -m PyInstaller --onefile --noconsole --name CaptureFaces --add-data "haarcascade_frontalface_default.xml;." --distpath . --workpath build --specpath build --collect-all cv2 capture_faces.py
.venv\Scripts\python.exe -m PyInstaller --onefile --noconsole --name TrainModel --distpath . --workpath build --specpath build --collect-all cv2 train_model.py
.venv\Scripts\python.exe -m PyInstaller --onefile --noconsole --name Recognize --add-data "haarcascade_frontalface_default.xml;." --distpath . --workpath build --specpath build --collect-all cv2 recognize.py
.venv\Scripts\python.exe -m PyInstaller --onefile --noconsole --name ManagePeople --distpath . --workpath build --specpath build --collect-all cv2 manage_people.pyUse an absolute path for haarcascade_frontalface_default.xml in
--add-data if you run these from outside the project directory — a relative
path resolves against --specpath, not your current directory.
capture_faces.py # webcam -> dataset/<name>/*.jpg
train_model.py # dataset/ -> trainer.yml + labels.pickle
recognize.py # webcam + trainer.yml -> live recognition
manage_people.py # table view + delete a person (and their data)
face_utils.py # shared helpers: low-light preprocessing, exe-safe paths, popups
dataset/ # captured face images (gitignored)
*.exe # compiled double-click apps (gitignored, rebuild from source)