An AI-powered identity verification system that combines real-time liveness detection, face registration, and ID card cross-verification using deep learning.
The system validates a user's identity through three sequential steps:
- Liveness Detection — Confirms the user is a real person (not a photo or deepfake) by tracking head movements in real time.
- Face Registration — Captures and stores a clear face image for future reference.
- Face + ID Verification — Cross-verifies the user's live face against their ID card photo and previously registered face.
| 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 |
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).
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.
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.
pytesseract is integrated for future use — such as extracting the name or ID number from the card to add text-based verification.
├── 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
- Python 3.8+
- Tesseract OCR installed (for OCR support)
- Webcam access
1. Create and activate a virtual environment
python -m venv venv2
# Windows
venv2\Scripts\activate
# macOS / Linux
source venv2/bin/activate2. Install dependencies
pip install -r requirements.txt3. (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.py5. Open in your browser
| Page | URL |
|---|---|
| Registration | http://127.0.0.1:5000/ |
| Verification | http://127.0.0.1:5000/verify-page |
- Go to the registration page.
- Allow webcam access.
- Follow the on-screen head movement instructions.
- Your face is captured and saved on liveness confirmation.
- 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.
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.
| 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 |
- 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.