Skip to content

jenniferlinet/face-idverification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Face + ID Verification System

An AI-powered identity verification system that combines real-time liveness detection, face registration, and ID card cross-verification using deep learning.


How It Works

The system validates a user's identity through three sequential steps:

  1. Liveness Detection — Confirms the user is a real person (not a photo or deepfake) by tracking head movements in real time.
  2. Face Registration — Captures and stores a clear face image for future reference.
  3. Face + ID Verification — Cross-verifies the user's live face against their ID card photo and previously registered face.

Tech Stack

Component Technology
Backend Framework Flask
Real-time Communication Flask-SocketIO
Face Detection MediaPipe
Face Recognition DeepFace (Facenet512)
Image Preprocessing OpenCV
OCR pytesseract
Frontend HTML, CSS, JavaScript
Utilities NumPy, Pillow, base64

Features

🔴 Liveness Detection (Anti-Spoofing)

Guides the user through sequential head movements via real-time webcam stream:

  • Look straight → Turn left → Turn right → Look straight

Tracks the nose tip x-coordinate from MediaPipe keypoints to detect genuine motion (not a static image or video replay).

📸 Face Registration

After liveness is confirmed, the backend captures and saves a face image. Image clarity is validated using Laplacian variance — blurry frames (below threshold 40.0) are automatically rejected.

🪪 ID Card Verification

The user uploads a live selfie and an ID card photo. The system:

  • Applies CLAHE (Contrast Limited Adaptive Histogram Equalization) to enhance low-contrast ID photos
  • Uses DeepFace to compare:
    • Live photo vs. ID card photo
    • Live photo vs. registered face

Both comparisons must pass for verification to succeed.

📝 OCR (Optional / Extendable)

pytesseract is integrated for future use — such as extracting the name or ID number from the card to add text-based verification.


Project Structure

├── app.py                  # Main Flask + SocketIO server
├── requirements.txt        # Python dependencies
├── registrations/          # Stored face registration images
└── templates/
    ├── register.html       # Liveness detection + face capture UI
    └── verify.html         # ID upload + verification UI

Getting Started

Prerequisites

  • Python 3.8+
  • Tesseract OCR installed (for OCR support)
  • Webcam access

Installation

1. Create and activate a virtual environment

python -m venv venv2
# Windows
venv2\Scripts\activate
# macOS / Linux
source venv2/bin/activate

2. Install dependencies

pip install -r requirements.txt

3. (Windows only) Set Tesseract path in app.py if needed:

pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'

4. Run the server

python app.py

5. Open in your browser

Page URL
Registration http://127.0.0.1:5000/
Verification http://127.0.0.1:5000/verify-page

Usage

Step 1 — Register

  • Go to the registration page.
  • Allow webcam access.
  • Follow the on-screen head movement instructions.
  • Your face is captured and saved on liveness confirmation.

Step 2 — Verify

  • Go to the verification page.
  • Upload a live selfie and your ID card photo.
  • The system compares both images against your registered face.
  • Result is displayed as a success or failure with a reason.

Key Concepts

Face Embedding — A 512-dimensional vector encoding unique facial features, generated by the Facenet512 model.

Cosine Similarity — Used to measure the distance between two face embeddings. A smaller distance means a closer match.

CLAHE — Contrast Limited Adaptive Histogram Equalization; improves visibility in poor-quality or uneven-lighting ID photos.

Laplacian Variance — A blur detection metric. Low variance = blurry image = rejected capture.

SocketIO — Enables bidirectional real-time communication for live video frame streaming between browser and server.


API Endpoints

Method Endpoint Description
GET / Registration page
GET /verify-page Verification page
WebSocket /video_frame Receives webcam frames for liveness detection
POST /verify-with-id Accepts live image + ID card; returns verification result

Notes

  • DeepFace runs locally — no face data is sent to external servers.
  • Registered face images are stored in the registrations/ directory.
  • The liveness check uses relative nose movement, not absolute pixel values, making it resolution-independent.

About

AI-powered Face and ID Verification System using Flask, OpenCV, MediaPipe, and DeepFace with real-time liveness detection.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors