A real-time face recognition system built using PyTorch and OpenCV. The system detects faces from a live camera feed, extracts deep facial embeddings, and identifies individuals by comparing them with a stored database.
- Real-time face detection using MTCNN
- Deep feature extraction using FaceNet (InceptionResnetV1)
- Face recognition using Euclidean Distance
- Multi-face support in a single frame
- Unknown face detection with alert
- Live statistics (Total / Known / Unknown)
- Real-time timestamp display
Camera → Face Detection → Face Alignment → Embedding Extraction → Comparison → Decision → Display
- Capture frame using OpenCV
- Detect faces using MTCNN
- Align and preprocess faces
- Extract embeddings using FaceNet
- Compare embeddings with database
- Identify person or label as "Unknown"
| Component | Technology |
|---|---|
| Framework | PyTorch |
| Face Detection | MTCNN |
| Feature Extraction | FaceNet (InceptionResnetV1) |
| Video Processing | OpenCV |
| Math Operations | NumPy |
| Data Storage | Pickle |
The system is based on Deep Metric Learning, not traditional classification.
Instead of predicting classes, the model:
- Converts faces → embeddings (vectors)
- Compares similarity using distance
d = √Σ(xᵢ - yᵢ)²
- Small distance → Same person
- Large distance → Different person
FaceRecognitionProject/
├── build_database.py ├── recognize_realtime.py ├── utils.py
├── Known_faces/ ├── database/
└── requirements.txt
pip install -r requirements.txt
python build_database.py
python recognize_realtime.py
- Uses pretrained models (no training required)
- Works offline after setup
- Accuracy depends on lighting, angle, and image quality
- Performance drops in low light
- Sensitive to occlusion (mask, glasses)
- CPU execution may be slower
- GPU acceleration
- Replace FaceNet with ArcFace
- Use Cosine Similarity
- Add Face Tracking
- Optimize search using FAISS
This project demonstrates how to build a complete real-time face recognition pipeline by combining Computer Vision, Deep Learning, and Metric Learning into a practical system.