A face authentication system built with Rust.
Face Auth is a modular face authentication system consisting of three main components:
- App - A Rust-based face authentication engine that handles face embedding generation, storage, and user authentication
- Camera Server - A Python FastAPI server that provides camera streaming capabilities with support for multiple camera sources
- Workshop - Educational exercises for learning face recognition concepts and implementation techniques
- 🎯 Real-time Face Authentication - Fast face recognition using ConvNeXt models
- 📹 Multiple Camera Sources - Support for OpenCV, libcamera, and custom video streams
- 💾 Local File Storage - Simple JSON-based storage for face embeddings
- 🌐 Web API - RESTful camera streaming API with dynamic camera switching
- 🔧 Easy Configuration - YAML-based configuration for all components
- 🚀 Cross-platform - Works on Windows, Linux, and Raspberry Pi
- 📚 Educational Workshop - Step-by-step exercises for learning face recognition
┌─────────────────┐ HTTP Stream ┌──────────────────┐
│ Camera Server │ ◄─────────────── │ Face Auth App │
│ (Python) │ │ (Rust) │
│ │ │ │
│ • FastAPI │ │
│ • OpenCV │ │ • Embedding Gen │
│ • libcamera │ │ • Authentication │
└─────────────────┘ └──────────────────┘
│ │
▼ ▼
┌─────────────────┐ ┌──────────────────┐
│ USB Camera │ │ Local Storage │
│ Raspberry Pi │ │ • JSON Files │
│ Webcam │ │ • Face Embeddings│
└─────────────────┘ └──────────────────┘
git clone https://github.com/Wyliodrin/edge-ai-face-auth.git
cd face-auth
cd workshop
cargo buildcd ~/WORKSHOP/camera_server
source venv/bin/activate
# Start the camera server
uvicorn camera_stream_api:app --host 0.0.0.0 --port 8000cd app
# Build the application
cargo build
# Run the application
cargo run-
Register a new user:
- Run the app and type
register - Enter a username
- Look at the camera while the system captures face samples
- Run the app and type
-
Authenticate:
- Type
login - Enter your username
- Look at the camera for authentication
- Type
The core authentication engine built with Rust for performance and safety.
Key Features:
- ConvNeXt-based face embedding generation
- Local file storage for face embeddings
- Real-time face capture and processing
- High-performance face matching algorithms
Dependencies:
candle-core&candle-nn- Neural network frameworkreqwest- HTTP client for video streamingimage&minifb- Image processing and display
Configuration:
# config.yaml
storage:
type: "local_file"
local_file:
path: "embeddings.json"
stream:
url: "http://localhost:8000/video_feed"
num_images: 5
interval_millis: 10
model:
name: "timm/convnext_atto.d2_in1k"A FastAPI-based streaming server that provides camera access with multiple source support.
Key Features:
- FastAPI web server with real-time streaming
- OpenCV and libcamera support
- Dynamic camera source switching
- Comprehensive error handling and logging
- Health check and diagnostic endpoints
Dependencies:
fastapi&uvicorn- Web framework and serveropencv-python- Computer vision librarypicamera2- Raspberry Pi camera support (optional)
API Endpoints:
GET /- Server status and camera infoGET /health- Health checkGET /video_feed- Video streamGET /camera_info- Detailed camera configurationGET /switch_camera?source={opencv|libcamera}- Switch camera source
A collection of progressive exercises designed to teach face recognition concepts and implementation.
Exercises:
- Exercise 01 - Image Processing - Loading and normalizing images for neural networks
- Exercise 02 - Embeddings - Computing face embeddings using ConvNeXt models
- Exercise 03 - Similarity - Implementing cosine similarity for face matching
- Exercise 04 - Storage - Building local file storage for face embeddings
- Exercise 05 - Retrieval - Implementing k-nearest neighbor search
Structure:
- Each exercise includes skeleton code with TODO comments
- Solutions provided for reference and verification
- Documentation and explanations
- Progressive difficulty building core concepts
cd ex0x..
cargo testFace embeddings are stored locally in JSON format (embeddings.json by default).
Benefits:
- Simple setup with no external dependencies
- Works offline and is easy to backup
- Human-readable format for debugging
- Suitable for development, testing, and small-scale deployments
Face Auth/
├── app/ # Rust face authentication engine
│ ├── src/
│ │ ├── main.rs # Application entry point
│ │ ├── config.rs # Configuration management
│ │ ├── embeddings/ # Face embedding generation
│ │ ├── storage/ # Storage implementations
│ │ └── image_utils/ # Image processing utilities
│ ├── config.yaml # App configuration
│ └── Cargo.toml # Rust dependencies
├── camera_server/ # Python camera streaming server
│ ├── camera_stream_api.py # FastAPI application
│ ├── requirements.txt # Python dependencies
│ └── config.env # Environment configuration
└── workshop/ # Workshop exercises
├── ex01_image_processing/ # Exercise 1: Image loading and normalization
├── ex02_embeddings/ # Exercise 2: Face embedding generation
├── ex03_similarity/ # Exercise 3: Cosine similarity computation
├── ex04_storage_local/ # Exercise 4: Local file storage implementation
├── ex05_retrieval/ # Exercise 5: k-NN search and retrieval
└── solution/ # Reference solutions for all exercises
-
Poor recognition accuracy:
- Ensure good lighting conditions
- Capture multiple face samples during registration
- Keep face centered and looking at camera
-
Video stream errors:
- Verify camera server is running on correct port
- Check network connectivity between components
-
Faster inference:
- Use release build:
cargo run --release - Adjust capture interval in config
- Use release build:
-
Memory usage:
- Limit number of face samples during capture
This project is licensed under the MIT License - see the individual component READMEs for details.
- Uses Candle framework for neural network inference
- Camera streaming powered by FastAPI
- Image processing with OpenCV and Rust image crate
For issues and questions:
- Check the Troubleshooting section
- Review component-specific READMEs in
app/andcamera_server/ - Open an issue in the repository
Face Auth - Secure, fast, and reliable face authentication for modern applications.