DEV Community

Syahrul Kahfi
Syahrul Kahfi

Posted on

Building a Real-Time Face Recognition Attendance System with Python, OpenCV, and Flask

By : Raden Gumilar Riyansyah, Iwan Muttaqin, Syahrul Kahfi, Riko Andrianto Tarigan, Khanes Setiyo Aji

In an era of increasing digital transformation, facial recognition is emerging as a modern and secure alternative to traditional attendance methods. In this article, I’ll walk you through how I built a real-time face recognition attendance system using Python, Flask, OpenCV, and the face_recognition library.
Enter fullscreen mode Exit fullscreen mode

This web-based system captures faces via webcam, verifies users against stored data, prevents duplicate check-ins or check-outs, and exports attendance records to Excel — making it ideal for offices, schools, or small organizations.

What This App Does
This facial recognition-based attendance system allows you to:
• Register users by storing facial images as datasets.
• Perform clock in and clock out using face verification.
• Block duplicate attendance attempts in a single day.
• View and export attendance logs to Excel files.

Tech Stack Overview
• Python — Core programming language.
• Flask — Web framework for routing and interface logic.
• OpenCV — Real-time image capture and face detection.
• face_recognition — Deep learning-based facial recognition.
• Pandas — Data processing and manipulation.
• XlsxWriter / openpyxl — Exporting attendance to Excel.

**Face Recognition Methods: OpenCV, LBP & CNN

OpenCV for Real-Time Face Capture**
OpenCV handles webcam access and frame processing :

video_capture = cv2.VideoCapture(0)
ret, frame = video_capture.read()

LBP (Local Binary Pattern)
LBP is a fast and lightweight face detection method based on pixel pattern comparisons, ideal for limited-resource systems:
face_cascade = cv2.CascadeClassifier('lbpcascade_frontalface.xml')
faces = face_cascade.detectMultiScale(gray_frame, scaleFactor=1.1, minNeighbors=5)

CNN (Convolutional Neural Network)
For face recognition, the face_recognition library uses a pre-trained CNN model (via dlib) to:
• Detect facial landmarks.
• Generate 128-dimensional face encodings (feature vectors).

User Interface Overview (Based on the UI PDF)
The Flask-based web interface includes:
Register Face — Capture and store a new user’s facial data.

Image description
Clock In / Clock Out — Attendance via facial recognition.

Image description

Image description
Attendance History — View logs of check-ins and check-outs.

Image description
Export to Excel — Downloadable attendance data.

Image description
• *Timer Settings *— Control the time windows for valid check-
ins/outs.

Image description

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.