A comprehensive computer vision project that performs real-time Face Detection, Identity Recognition, Emotion Analysis, and Gender Classification using a webcam feed.
The system combines MediaPipe , dlib/face_recognition , and TensorFlow/Keras.
- Multi-Task Analysis: Simultaneously predicts Identity, Emotion, and Gender for every face in the frame.
- High-Performance Detection: Uses Google's MediaPipe for ultra-fast face tracking, even on CPU.
- Dynamic Database: Add new faces to the database instantly while the program is running.
- Persistent Storage: Automatically saves and loads known face encodings from
known_faces.pkl. - Stats Tracking: Keeps track of how many times each known person has been seen.
- Python 3.10 or 3.11 (Recommended).
- Note: Python 3.12+ is currently incompatible with some TensorFlow/dlib features.
- Visual Studio C++ Build Tools (Required for Windows users to compile
dlib). - Webcam
├── **Standard Version**
├── FaceRecognitionV2.py # Main application script
├── requirements.txt # Python dependencies
├── known_faces.pkl # Database of registered face encodings
├── emotionModel.hdf5 # Pre-trained Keras model for Emotion detection (48x48)
├── genderModel.hdf5 # Pre-trained Keras model for Gender detection (64x64)
└── face_recognition_output/ # Directory where saved face images are stored
It is highly recommended to use a clean virtual environment to avoid version conflicts.
Windows:
Bash
python -m venv venv
.\venv\Scripts\activate
Mac/Linux:
Bash
python3 -m venv venv
source venv/bin/activate
The webcam feed will open automatically.
Press s: Save the current face to the database. You will be prompted in the terminal to type a name.
Press q or Esc: Quit the program.
Critical Step: If you are on Windows, ensure you have installed the "Desktop development with C++" workload via Visual Studio Build Tools before running this.
Bash
pip install -r requirements.txt
TensorFlow and dlib often conflict with the newest Numpy versions. Downgrade Numpy to ensure stability:
Bash
pip install "numpy<2"