This project is a from-scratch implementation of a basic Face Recognition and Emotion Detection system using Python, TensorFlow, and OpenCV.
- Custom Face Recognition: Train the model on your own dataset of faces (no pre-downloaded datasets).
- Emotion Detection: Classify faces into emotions such as Happy, Sad, Neutral, and Surprised.
- Webcam Integration: Capture and label training images directly from your webcam.
- Lightweight Model: Small and fast to train, focused on learning the fundamentals.
- Educational Focus: Demonstrates the machine learning pipeline rather than competing with production-grade systems.
python -m venv .venv
source .venv/bin/activate # Mac/Linux
.venv\Scripts\activate # Windowspip install -r requirements.txt- tensorflow
- opencv-python
- numpy
- matplotlib
Use the webcam capture script to collect images for each person/emotion. (Note: the data/ folder is git-ignored, so your personal images won’t be uploaded.)
Example:
python capture.py --type person --label NAME --count 200
python capture.py --type emotion --label EMOTION --count 200python train_face_recognizer.py
python train_emotion_cnn.pypython realtime_demo.pyface-emotion-project/
├─ capture.py
├─ train_face_recognizer.py
├─ train_emotion_cnn.py
├─ realtime_demo.py
├─ requirements.txt
├─ models/
└─ data/
├─ faces/ # for face recognition: data/faces/<person_name>/<img>.jpg
└─ emotions/ # for emotion training: data/emotions/<emotion_label>/<img>.jpg