Skip to content

Latest commit

Β 

History

88 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” SecureFace AI

Python Flask MediaPipe InsightFace MongoDB License

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.


πŸš€ Live Demo

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.


πŸ“Œ Features

  • πŸ‘€ 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

πŸ“· Application Preview

Page Preview
Landing Page Landing Page
User Registration Registration
Login Login
Dashboard Dashboard
Face Detection Preview Face Detection Preview
Face Comparison Tool Face Detection Preview

πŸŽ₯ Demo Videos / GIFs

  • Demo: Login Demo

πŸ–₯ Demo Walkthrough

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

Preview Page

  • Live webcam preview
  • Real-time face detection
  • Displays face detection results
  • Redirects to Face Similarity page

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

πŸ— Project Architecture

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

βš™οΈ Technology Stack

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

🧠 AI Pipeline

Registration Flow

User β†’ Capture Face β†’ MediaPipe Face Detection β†’ Face Crop
     β†’ InsightFace Embedding β†’ Generate User ID β†’ Hash Password
     β†’ Store User Data β†’ MongoDB

Login Flow

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

Face Recognition Pipeline

Input Image β†’ MediaPipe Face Detection β†’ Face Crop
            β†’ InsightFace ArcFace β†’ 512-D Face Embedding
            β†’ Cosine Similarity β†’ Euclidean Distance
            β†’ Authentication Result

Face Similarity Pipeline

Image 1 
      β”‚
      β–Ό
Generate Embedding
      β”‚
      β–Ό
Image 2
      β”‚
      β–Ό
Generate Embedding
      β”‚
      β–Ό
Cosine Similarity
      β”‚
      β–Ό
Euclidean Distance
      β”‚
      β–Ό
Match Decision

πŸ“Š Face Matching

The system compares two facial embeddings using:

  • Cosine Similarity
  • Euclidean Distance

Authentication succeeds only if both similarity metrics satisfy predefined thresholds.


πŸ›‘οΈ Active Anti-Spoofing & Liveness Detection

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 solvePnP and 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.

πŸ”’ Security Features

  • Password Hashing using Scrypt
  • Session Authentication
  • Environment Variables
  • Face Authentication
  • User ID Validation
  • Email Validation

πŸ“‚ Database Schema

Each registered user record contains:

Field Description
User ID Unique Generated ID
Name User Name
Email User Email
Password Hashed Password
Face Embedding 512-D Vector
Created At Registration Date

πŸ§ͺ Testing

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.


πŸ“Š Performance Evaluation

SecureFace AI was evaluated on publicly available benchmark datasets to measure face detection and face verification performance.

πŸ“Œ Evaluation Datasets

Dataset Purpose Images / Pairs
CelebA Face Detection & Authentication Validation 10,000 Images
LFW (Labeled Faces in the Wild) Face Verification 101,374 Verification Pairs

😊 Face Detection Evaluation (CelebA)

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.

πŸ” Face Verification Evaluation (LFW)

  • 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
ROC Confusion Matrix Similarity Distribution

Evaluation Pipeline

LFW Dataset β†’ Generate Face Embeddings β†’ Create Verification Pairs
            β†’ Compute Similarity Scores β†’ Threshold Optimization
            β†’ Evaluate Verification β†’ Performance Metrics

πŸ“Œ Summary

  • βœ… 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

πŸ“¦ Installation

1. Clone Repository

git clone https://github.com/kumar-shanu-1881/Secure_Face_AI.git
cd SecureFace-AI

2. Create Virtual Environment

python -m venv faceenv

Activate:

# Windows
faceenv\Scripts\activate

# Linux/Mac
source faceenv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Configure Environment Variables

Create a .env file:

MONGO_URI=your_mongodb_connection_string
SECRET_KEY=your_secret_key

5. Run Project

python run.py

Application will run at: http://127.0.0.1:10000


πŸ“ˆ Future Improvements

  • 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

🎯 Project Highlights

  • 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

πŸ‘¨β€πŸ’» Author

Kumar Shanu B.Tech Computer Science Engineering (AI & ML) Machine Learning & Full Stack Developer


⭐ Support

If you found this project useful, consider giving it a star on GitHub!

About

πŸš€ SecureFace AI is an intelligent face authentication system that enables secure user registration and login using facial recognition technology. It integrates MediaPipe for face detection, InsightFace (Buffalo_SC) for high-accuracy facial embeddings, Flask for backend APIs, and MongoDB Atlas for secure data storage. The system verifies users by c

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages