DEV Community

Cover image for πŸ”₯ FaceLocking: Enterprise Face Recognition Without the $$$β€”Track Behavior in Real-Time on CPU Alone
Fabrice
Fabrice

Posted on

πŸ”₯ FaceLocking: Enterprise Face Recognition Without the $$$β€”Track Behavior in Real-Time on CPU Alone

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

πŸ“ 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
Enter fullscreen mode Exit fullscreen mode

🎯 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

  1. Face recognition is accessible – With modern libraries, you don't need a Ph.D. in deep learning
  2. CPU performance is underrated – Modern CPUs can handle real-time face processing
  3. Threshold tuning matters – The difference between 90% accuracy and 99% accuracy is data-driven evaluation
  4. Behavioral tracking is powerful – Knowing what someone does is as useful as knowing who they are
  5. 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!
Enter fullscreen mode Exit fullscreen mode

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.

Star us on GitHub! ⭐

Top comments (0)