FaceLocking: CPU-Powered Face Recognition with Behavioral Tracking
GitHub Repository: github.com/fabishz/FaceLocking
π― Inspiration
In the age of AI and machine learning, most cutting-edge computer vision systems demand expensive GPUs and complex cloud infrastructure. But what if you need robust face recognition on a standard laptop? What if you want to understand not just who someone is, but what they're doing over time?
We built FaceLocking to answer these questions. This project combines state-of-the-art face recognition with behavioral trackingβenabling real-time identification and action monitoring using only CPU resources. Perfect for security systems, accessibility features, behavioral analysis, and educational exploration of modern face recognition.
π What It Does
FaceLocking is a complete end-to-end face recognition and behavioral tracking system that:
Core Recognition Capabilities
- Identifies faces using ArcFace embeddingsβthe same technology powering enterprise facial recognition systems
- Recognizes multiple people simultaneously in real-time (10-20 FPS on CPU)
- Rejects unknown faces automatically with a tunable confidence threshold
- Works offline with persistent database storage (no cloud required, no API costs)
Behavioral Tracking (The Game-Changer)
- Locks onto target identities and maintains stable tracking across frames
- Detects behavioral actions: head movements (left/right), eye blinks, and smiles
- Records comprehensive action logs with millisecond precision timestamps
- Generates persistently stored reports in human-readable format
Why This Matters
Most face recognition systems answer one question: "Who is this person?" FaceLocking answers a second, equally important question: "What is this person doing?" This opens entirely new applications:
- Security monitoring (detect unusual patterns)
- Behavioral research (analyze facial expressions and movements)
- Accessibility (enable hands-free control based on gestures)
- Educational datasets (understand face recognition algorithms in depth)
π‘ Key Technical Innovations
1. CPU-First Architecture
No GPUs requiredβruns on any modern laptop or server. This makes the system:
- Affordable β No expensive hardware or cloud subscriptions
- Portable β Deploy anywhere without infrastructure
- Private β Process sensitive data locally without sending to cloud APIs
- Accessible β Lower barrier to entry for students and researchers
2. 5-Point Landmark Alignment
Uses MediaPipe's efficient 5-point face landmarks to:
- Normalize faces to a canonical 112Γ112 pose
- Ensure consistent embedding extraction
- Enable geometric action detection (blinks, movements, expressions)
3. Principled Threshold Tuning
Includes built-in tools to analyze:
- FAR (False Accept Rate) β How often unknown faces are accepted
- FRR (False Reject Rate) β How often known faces are rejected
- Recommends optimal thresholds using ROC curve analysis
4. Modular Testing Pipeline
Each component can be tested independently:
python -m src.camera # Test camera access
python -m src.detect # Test face detection
python -m src.landmarks # Test landmark extraction
python -m src.align # Test alignment quality
python -m src.embed # Test embedding extraction
This educational approach makes the system transparent and debuggable.
ποΈ System Architecture
Enrollment β Detection β Alignment β Embedding β Database
β
Recognition β Detection β Alignment β Embedding β Matching
β
Face Locking β Lock Manager β Action Detection β History Logging
Key Components:
- Haar Cascade Detection β Fast, CPU-efficient face localization
- MediaPipe 5-Point Landmarks β Robust facial landmark extraction
- ArcFace ONNX Model β 512-dimensional embeddings via ResNet-50
- Cosine Distance Matching β Simple, interpretable similarity metric
- State Machine Lock Manager β Stable tracking with 20-frame tolerance
- Geometric Action Detectors β Movement, blinks, smiles using landmark geometry
π Performance
Typical performance on standard CPU hardware:
- Enrollment: 10β15 FPS (capturing reference samples)
- Recognition: 10β20 FPS (single face)
- Recognition: 8β15 FPS (2β3 faces simultaneously)
- Face Locking: 10β18 FPS (with action detection)
Optimizations employed:
- Region-of-interest cropping reduces redundant computation
- Selective frame processing (every Nth frame)
- Temporal smoothing stabilizes predictions
- Efficient geometric calculations for action detection
π Educational Value
This project is ideal for learning:
β Computer Vision Fundamentals
- Face detection and alignment
- Feature extraction and embeddings
- Similarity matching and classification
β Deep Learning
- ONNX model inference
- Vector space embeddings (why 512 dimensions?)
- Metric learning (ArcFace loss)
β Software Engineering
- Modular system design
- Real-time processing pipelines
- Database design and persistence
- State machines for robust behavior
β ML Operations
- Threshold tuning and ROC analysis
- FAR/FRR tradeoffs
- A/B testing methodology
- Performance benchmarking
π Getting Started
Installation (5 minutes)
# Clone the repository
git clone https://github.com/fabishz/FaceLocking.git
cd FaceLocking
# Create virtual environment
python -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Initialize project structure
python init_project.py
# Download ArcFace model (~120MB)
curl -L -o buffalo_l.zip \
"https://sourceforge.net/projects/insightface.mirror/files/v0.7/buffalo_l.zip/download"
unzip -o buffalo_l.zip
cp w600k_r50.onnx models/embedder_arcface.onnx
Quick Start (10 minutes)
# Enroll a person
python -m src.enroll
# β Capture 15+ samples (press SPACE to capture, 'a' for auto-capture, 's' to save)
# Run recognition
python -m src.recognize
# β See faces detected in real-time with identity labels
# Track behavior with Face Locking
python -m src.face_locking
# β Select a target identity and watch their actions get logged
# Check the generated history file
cat data/action_history/[identity]_history_[timestamp].txt
π Project Structure
FaceLocking/
βββ src/
β βββ camera.py # Camera testing
β βββ detect.py # Face detection test
β βββ landmarks.py # Landmark extraction test
β βββ align.py # Face alignment test
β βββ embed.py # Embedding extraction test
β βββ enroll.py # Enrollment pipeline
β βββ evaluate.py # Threshold optimization
β βββ recognize.py # Real-time recognition
β βββ face_locking.py # Face locking & behavioral tracking
β βββ haar_5pt.py # Core detection module
βββ models/
β βββ embedder_arcface.onnx # ArcFace model
βββ data/
β βββ db/ # Recognition database
β βββ enroll/ # Reference samples
β βββ action_history/ # Timestamped action logs
βββ requirements.txt
βββ init_project.py
βββ README.md
π― Use Cases
1. Security & Surveillance
Lock onto specific individuals and monitor their activities. Automatic alerts on unusual patterns.
2. Behavioral Analysis
Research facial expressions and movements in controlled studies. Generate detailed action logs for analysis.
3. Accessibility
Enable hands-free control for users with mobility limitations. Blink detection for eye-gaze interfaces.
4. Education
Transparent, modular codebase teaches every step of face recognition. Debug and test each component independently.
5. Privacy-Preserving Analytics
Process video locally without cloud services. Maintain data sovereignty and compliance (GDPR, etc.).
π What Makes This Different
| Feature | FaceLocking | Cloud APIs | Desktop Apps |
|---|---|---|---|
| Offline Processing | β Yes | β No | β Yes |
| No GPU Required | β Yes | N/A | β Often Required |
| Transparent Algorithms | β Yes | β Proprietary | β οΈ Varies |
| Behavioral Tracking | β Yes | β No (mostly) | β Rare |
| Data Privacy | β Yes | β Sent to cloud | β Yes |
| Cost | β Free | β Pay-per-call | β Free |
| Educational Value | β High | β Black box | β οΈ Limited |
π οΈ Technologies Used
- Python 3.9+ β Core implementation
- OpenCV β Image processing and Haar cascade detection
- MediaPipe β 5-point facial landmark extraction
- ONNX Runtime β Efficient ArcFace model inference
- NumPy & SciPy β Mathematical operations and statistics
- Scikit-learn β ROC curve analysis for threshold tuning
π What We Learned
- Face recognition is accessible β With modern libraries, you don't need a Ph.D. in deep learning
- CPU performance is underrated β Modern CPUs can handle real-time face processing
- Threshold tuning matters β The difference between 90% accuracy and 99% accuracy is data-driven evaluation
- Behavioral tracking is powerful β Knowing what someone does is as useful as knowing who they are
- Transparency builds trust β Explainable algorithms make systems more trustworthy and debuggable
π Future Enhancements
- Multi-threaded processing for higher FPS on multi-core systems
- Advanced action detection (head pose estimation, gaze tracking)
- Integration with face mask detection
- Temporal action pattern recognition (sequences of actions)
- Export to popular formats (ONNX, TensorFlow for further optimization)
- Web interface for remote monitoring
- Integration with security system APIs
π References
- Deng et al. (2019) β ArcFace: Additive Angular Margin Loss for Deep Face Recognition
- InsightFace Project β 2D & 3D Face Analysis
- MediaPipe β Efficient ML Pipelines for Mobile and Desktop
- ONNX β Open Neural Network Exchange Format
π About the Project
FaceLocking was developed as an educational platform to make advanced face recognition accessible to developers, researchers, and students worldwide. It prioritizes:
- Transparency β Clear, understandable code over black boxes
- Accessibility β CPU-first to lower barriers to entry
- Modularity β Test each component independently
- Production-readiness β Database persistence, error handling, configuration management
π Get Involved
This is an open-source educational project. We welcome:
- Contributions β Fork, improve, submit pull requests
- Bug reports β Help us improve reliability
- Feature requests β Suggest new detection capabilities
- Documentation β Help us explain concepts better
- Use cases β Show us how you're using FaceLocking
π Full Documentation
For detailed installation, usage, and API documentation, visit:
GitHub Repository: github.com/fabishz/FaceLocking
π¬ Try It Now
git clone https://github.com/fabishz/FaceLocking.git
cd FaceLocking
python init_project.py
python -m pip install -r requirements.txt
python -m src.recognize # See face recognition in action!
No GPU. No cloud services. No credit card. Just pure, transparent face recognition and behavioral tracking.
Built with β€οΈ for developers, researchers, and everyone curious about how face recognition really works.
Top comments (0)