A real-time face recognition application using a pre-trained Keras model (Teachable Machine) and OpenCV. The app detects faces from a live webcam feed, identifies recognized individuals, and displays bounding boxes with confidence scores.
- 🎥 Real-Time Detection — Live webcam feed with face detection using Haar Cascade classifier
- 🧠 Face Recognition — Identifies faces using a pre-trained Keras model (Teachable Machine)
- 📊 Confidence Scores — Displays recognition confidence percentage for each detected face
- 🟩 Visual Overlays — Green bounding boxes and labeled name tags on detected faces
- ⚙️ Configurable Threshold — Adjustable confidence threshold (default: 65%) to control recognition sensitivity
| Component | Technology |
|---|---|
| Language | Python 3.8+ |
| Face Detection | OpenCV Haar Cascade |
| Face Recognition | TensorFlow/Keras (Teachable Machine model) |
| Image Processing | OpenCV, NumPy |
- Python 3.8+ installed
- A webcam connected to your computer
- (Optional) Train your own model at Teachable Machine
-
Clone the repository
git clone https://github.com/your-username/face-recognition.git cd face-recognition -
Create a virtual environment
python -m venv .venv
-
Activate the virtual environment
- Windows:
.venv\Scripts\activate
- macOS/Linux:
source .venv/bin/activate
- Windows:
-
Install dependencies
pip install opencv-python numpy tf-keras
-
Run the application
python app.py
-
Press
qto quit the webcam window
- Face Detection — OpenCV's Haar Cascade classifier detects faces in each webcam frame
- Preprocessing — Detected face regions are resized to 224×224 pixels and normalized to [-1, 1] range
- Recognition — The pre-trained Keras model predicts the identity from the preprocessed image
- Display — Bounding boxes and confidence-labeled name tags are drawn on recognized faces
- Go to Google Teachable Machine
- Create an Image Project
- Add classes for each person you want to recognize
- Train the model and export as Keras (
.h5format) - Replace
keras_model.h5and updatelabels.txtwith your class names
0 Person_Name_1
1 Person_Name_2
2 Person_Name_3
face-recognition/
├── app.py # Main application with webcam loop
├── keras_model.h5 # Pre-trained Keras model (Teachable Machine)
├── labels.txt # Class labels for recognition
├── .gitignore
└── README.md
You can adjust these constants in app.py:
| Constant | Default | Description |
|---|---|---|
INPUT_SIZE |
224 | Model input resolution |
CONFIDENCE_THRESHOLD |
0.65 | Minimum confidence to display a name |
BOX_COLOR |
Green | Bounding box color (BGR) |
FONT_SCALE |
0.7 | Label text size |
This project is open source and available under the MIT License.
Sujitha Kotyada — @sujitha-kotyada