A C++ application using GTKmm and OpenCV for real-time face capture, training, and recognition. Also includes a standalone Python script using the dlib-based face_recognition library.
This project provides:
-
C++ GUI Application (GTKmm + OpenCV):
- Capture face images using a webcam
- Train an LBPH model from captured faces
- Real-time face detection (Haar Cascade) and recognition (LBPH)
-
Python Script (
src/facedetection.py):- Standalone real-time face recognition using the
face_recognitionlibrary - Uses pre-captured images from
data/faces/as known faces - Multi-threaded processing for smoother video
- Standalone real-time face recognition using the
face-recognition/
├── data/
│ └── faces/ # Captured face images (.jpg) - created by setup
├── models/ # Haar Cascade models (downloaded by setup)
│ ├── haarcascade_frontalface_alt2.xml
│ └── haarcascade_eye.xml
├── src/
│ ├── main_gui.cpp # C++ GUI and main logic
│ ├── FaceRecognizer.cpp # LBPH recognition implementation
│ ├── FaceRecognizer.hpp
│ └── facedetection.py # Python face recognition script
├── tests/
│ ├── test.mp4
│ └── test.png
├── setup.sh # Downloads models, runs cmake
├── CMakeLists.txt
├── requirements.txt # Python dependencies
└── README.md
Generated at runtime (not in repo): models/face_model.yml, models/label_mapping.txt
- C++17 compiler (GCC, Clang)
- CMake 3.10+
- OpenCV (C++): Core, ImgProc, HighGUI, ObjDetect, Face, ML, VideoIO
- GTKmm 4.0
- Python 3.x
- opencv-python
- face-recognition (uses dlib)
chmod +x setup.sh
./setup.sh
cd build && makeIf setup fails due to missing dependencies:
Fedora/CentOS:
sudo dnf install cmake gcc-c++ opencv-devel gtkmm4.0-develDebian/Ubuntu:
sudo apt install build-essential cmake libopencv-dev libgtkmm-4.0-devManual model download (if setup fails):
mkdir -p models
curl -L -o models/haarcascade_frontalface_alt2.xml https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_frontalface_alt2.xmlRun from the project root (paths are relative):
./build/bin/FaceRecognitionGuipip install opencv-python face-recognition
python src/facedetection.pyUses webcam, reads known faces from data/faces/*.jpg (filename without extension = person name). Press q to quit.
On Wayland, you may need:
QT_QPA_PLATFORM=xcb python src/facedetection.py-
Capture: Enter a name, click Capture 10 times with your face visible. Images saved to
data/faces/. Note: starting a new capture session clears existing images in that folder. -
Train: Click "Train Model" to build the LBPH model from
data/faces/. Createsface_model.ymlandlabel_mapping.txt. -
Detect: Click "Start Detection" to recognize faces. Green box = recognized, red = unknown.
- Face detection: Haar Cascade (haarcascade_frontalface_alt2)
- Face recognition: LBPH (Local Binary Patterns Histograms) with adaptive confidence threshold
- Camera not detected: Check webcam is connected and not in use elsewhere
- Build fails: Install OpenCV and GTKmm dev packages (see Setup)
- Poor recognition: Better lighting, capture from varied angles, ensure face is large enough in frame