A real-time Face Authentication System built using Flask, MediaPipe, InsightFace (ArcFace), and MongoDB. SecureFace AI authenticates users using both traditional credentials and biometric facial recognition for enhanced security.
SecureFace AI (Live Demo): π https://secure-face-ai.onrender.com
β οΈ Note (Render Free Tier)This application is deployed on Render Free Tier. Free instances automatically spin down after periods of inactivity and have limited CPU/memory resources. As a result:
- The first request may take 30β60 seconds while the server wakes up.
- During heavy usage (especially webcam-based registration and authentication), the service may become slow or temporarily restart.
- If the live demo is unavailable, wait a moment and refresh, or refer to the screenshots and demo video below.
The application runs reliably in a local environment, where these hosting limitations do not apply.
- π€ User Registration
- π Secure Login using Face + Password
- π· Real-Time Webcam Face Capture
- π Face Detection using MediaPipe
- π§ Face Recognition using InsightFace (ArcFace)
- π 512-D Face Embeddings
- π‘οΈ Active Anti-Spoofing & Liveness Detection
- π Cosine Similarity & Euclidean Distance Matching
- π Face Detection Preview Page
- π Face Similarity Comparison Tool
- π Password Hashing (Werkzeug - Scrypt)
- πΎ MongoDB Database Integration
- π Automatic User ID Generation
- β³ Session-based Authentication (2 Days)
- π± Responsive User Interface
- π§ͺ Face Similarity Testing Module
| Page | Preview |
|---|---|
| Landing Page | ![]() |
| User Registration | ![]() |
| Login | ![]() |
| Dashboard | ![]() |
| Face Detection Preview | ![]() |
| Face Comparison Tool | ![]() |
Landing Page
- Project Introduction
- Features Overview
- Login/Register Navigation
Registration
- User Details
- Live Face Capture
- Face Embedding Generation
- Secure Password Storage
Login
- User ID Verification
- Email Verification
- Password Verification
- Live Face Verification
- Dashboard Access
Dashboard
- User Profile
- Project Information
- Authentication Status
- Technology Stack
- Live webcam preview
- Real-time face detection
- Displays face detection results
- Redirects to Face Similarity page
- Upload two face images
- Generates embeddings using InsightFace
- Compares embeddings using: β’ Cosine Similarity β’ Euclidean Distance
- Displays: β’ Match / No Match β’ Cosine Similarity Score β’ Euclidean Distance
SecureFace AI
β
βββ app
β β
β βββ api
β β βββ detect.py
β β βββ register.py
β β βββ login.py
β β βββ dashboard.py
β β βββ logout.py
β β βββ checksimilarity.py
β β
β βββ core
β β βββ face_detector.py
β β βββ get_embedings.py
β β βββ check_similarity.py
β β βββ anti_spoofing.py
β β
β βββ db
β β βββ mongodb.py
β β βββ user_repo.py
β β
β βββ __init__.py
β
βββ image
βββ static
βββ templates
βββ test
β
βββ .env
βββ requirements.txt
βββ run.py
βββ README.md
| Category | Technologies |
|---|---|
| Backend | Python, Flask, REST API |
| Frontend | HTML5, CSS3, JavaScript, Fetch API |
| Computer Vision | OpenCV, MediaPipe |
| Face Recognition | InsightFace, ArcFace (buffalo_sc) |
| Machine Learning | NumPy |
| Database | MongoDB Atlas |
| Security | Werkzeug Security (Scrypt), Flask Sessions, Environment Variables |
User β Capture Face β MediaPipe Face Detection β Face Crop
β InsightFace Embedding β Generate User ID β Hash Password
β Store User Data β MongoDB
User β Capture Live Stream β MediaPipe Face Detection
β Liveness & Anti-Spoof Gate (EAR Blink + 3D Pose)
βββ Failed βββΊ Reject (Spoof / Inactive Detected)
βββ Passed βββΊ InsightFace (ArcFace 512-D Embedding)
β Vector Similarity Verification (Cosine + Euclidean)
β Scrypt Password Check β Session Created β Dashboard
Input Image β MediaPipe Face Detection β Face Crop
β InsightFace ArcFace β 512-D Face Embedding
β Cosine Similarity β Euclidean Distance
β Authentication Result
Image 1
β
βΌ
Generate Embedding
β
βΌ
Image 2
β
βΌ
Generate Embedding
β
βΌ
Cosine Similarity
β
βΌ
Euclidean Distance
β
βΌ
Match Decision
The system compares two facial embeddings using:
- Cosine Similarity
- Euclidean Distance
Authentication succeeds only if both similarity metrics satisfy predefined thresholds.
To eliminate presentation attacks (printed photos, video replays, mobile screens), SecureFace AI incorporates a zero-GPU liveness verification layer before running biometric matching:
-
Eye Aspect Ratio (EAR) State Machine: Tracks 6 facial landmarks per eye using MediaPipe Face Mesh. A deterministic Finite State Machine validates the complete biological blink trajectory (
$\text{OPEN} \rightarrow \text{CLOSED} \rightarrow \text{OPEN}$ ) within a physiological window of 30msβ330ms. -
3D Head Pose Estimation (PnP): Maps 2D landmark coordinates to a canonical 3D human head model using OpenCV's
solvePnPand Euler angle decomposition (RQDecomp3x3) to calculate real-time Yaw, Pitch, and Roll. -
Temporal Anti-Tamper Engine:
- 4.0-second time-decay window on verified liveness events.
- Multi-frame dropout grace period to withstand network jitter over HTTP.
- Instant state reset on face occlusions or identity swaps.
- Password Hashing using Scrypt
- Session Authentication
- Environment Variables
- Face Authentication
- User ID Validation
- Email Validation
Each registered user record contains:
| Field | Description |
|---|---|
| User ID | Unique Generated ID |
| Name | User Name |
| User Email | |
| Password | Hashed Password |
| Face Embedding | 512-D Vector |
| Created At | Registration Date |
Face Detection
- Detect face successfully
- Face crop validation
Face Embedding
- Generate 512-dimensional embeddings
Similarity Testing
- Same Person Matching
- Different Person Matching
- Outputs: Cosine Similarity, Euclidean Distance, Match Decision
Results are stored in similarity_results.csv.
SecureFace AI was evaluated on publicly available benchmark datasets to measure face detection and face verification performance.
| Dataset | Purpose | Images / Pairs |
|---|---|---|
| CelebA | Face Detection & Authentication Validation | 10,000 Images |
| LFW (Labeled Faces in the Wild) | Face Verification | 101,374 Verification Pairs |
| Metric | Result |
|---|---|
| Images Evaluated | 10,000 |
| Face Detected | 9,997 (99.97%) |
| Single Face Validation | 9,946 (99.46%) |
| Authentication Passed | 5,312 (53.12%) |
| Average Detection Time | 90.87 ms |
| Processing Speed | 11 FPS |
Why is the Authentication Pass Rate Lower?
SecureFace AI is designed for secure biometric authentication, not general face detection. Authentication succeeds only when:
- Exactly one face is present
- The face is clearly visible
- The user is looking directly at the camera
- Proper frontal facial alignment is detected
Side-view and profile images in the CelebA dataset are therefore intentionally rejected to improve real-world authentication security.
- Generated face embeddings using InsightFace ArcFace (buffalo_sc)
- Created 101,374 verification pairs
- Optimized similarity thresholds via exhaustive threshold search (230+ combinations)
Optimized Thresholds
| Metric | Value |
|---|---|
| Cosine Similarity | β₯ 0.50 |
| Euclidean Distance | β€ 1.00 |
Verification Results
| Metric | Value |
|---|---|
| Verification Accuracy | 93.88% |
| Precision | 100.00% |
| Recall | 87.76% |
| F1 Score | 93.48% |
| ROC-AUC | 0.9944 |
| False Acceptance Rate (FAR) | 0.00% |
| False Rejection Rate (FRR) | 12.24% |
Confusion Matrix
| Predicted Different | Predicted Same | |
|---|---|---|
| Actual Different | 50,687 | 0 |
| Actual Same | 6,204 | 44,483 |
Evaluation Graphs
| ROC Curve | Confusion Matrix | Similarity Distribution |
|---|---|---|
![]() |
![]() |
![]() |
Evaluation Pipeline
LFW Dataset β Generate Face Embeddings β Create Verification Pairs
β Compute Similarity Scores β Threshold Optimization
β Evaluate Verification β Performance Metrics
- β Real-time Face Authentication System
- β MediaPipe Face Detection
- β InsightFace ArcFace Recognition
- β 512-D Face Embeddings
- β Threshold Optimization
- β Evaluated on 101,374 Verification Pairs
- β 93.88% Verification Accuracy
- β 100% Precision
- β ROC-AUC: 0.9944
- β 0% False Acceptance Rate
1. Clone Repository
git clone https://github.com/kumar-shanu-1881/Secure_Face_AI.git
cd SecureFace-AI2. Create Virtual Environment
python -m venv faceenvActivate:
# Windows
faceenv\Scripts\activate
# Linux/Mac
source faceenv/bin/activate3. Install Dependencies
pip install -r requirements.txt4. Configure Environment Variables
Create a .env file:
MONGO_URI=your_mongodb_connection_string
SECRET_KEY=your_secret_key5. Run Project
python run.pyApplication will run at: http://127.0.0.1:10000
- JWT Authentication
- PostgreSQL Support
- Qdrant Vector Database
- Docker Deployment
- Redis Session Storage
- Admin Dashboard
- Authentication Logs
- Email Verification
- Password Reset
- Face Registration History
- Multi-Factor Authentication
- Real-Time Face Authentication
- Secure User Registration
- Face + Password Login β’ Face Detection Preview Module
- InsightFace ArcFace Recognition
- MediaPipe Face Detection
- MongoDB Integration
- Flask Modular Architecture
- Session-Based Authentication
- Face Similarity Evaluation
- Production-Oriented Design β’ Face Similarity Comparison Tool β’ Flask REST APIs β’ Dual Metric Verification β’ Threshold Optimization β’ Evaluation Framework β’ ArcFace 512-D Embeddings
Kumar Shanu B.Tech Computer Science Engineering (AI & ML) Machine Learning & Full Stack Developer
- GitHub: https://github.com/kumar-shanu-1881/
- LinkedIn: https://www.linkedin.com/in/kumar-shanu-9219a5293/
If you found this project useful, consider giving it a star on GitHub!









