Back to Projects ArchivePython Application Development
Completed ProjectRole: Software Engineer

QR Attendance System

A desktop attendance recording application using OpenCV for live video feed capture, pyzbar for QR barcode decoding, and SQLite for structured local record persistence.

Problem statement

Manual event and classroom attendance tracking is prone to transcription errors, proxy sign-ins, and slow throughput. A lightweight, locally hosted solution is needed that operates without expensive proprietary biometric hardware or internet dependency.

Motivation and intended users

To build an end-to-end Python application integrating real-time computer vision, input validation, and transactional database persistence in SQLite.

Technologies and stack
PythonOpenCVpyzbarSQLite3NumPy

QR Attendance System: Architecture & Implementation

Architecture & Data Flow

text
[Camera Sensor]
       ↓ (OpenCV VideoCapture)
[Frame BGR Matrix]
       ↓
[pyzbar.decode()] ─── (Find QR Position & Read Payload)
       ↓
[Payload Parser & Schema Validation]
       ↓
[Duplicate Check Query (SQLite)] ── (Already recorded for current date/session?)
       ├─ If Duplicate ──> Render Amber Alert Overlay (Skip Write)
       └─ If New Valid  ──> Begin SQL Transaction
                                 ↓
                            INSERT INTO attendance (student_id, session_id, scan_time)
                                 ↓
                            Render Green Success Overlay & Audio Beep

Database Schema Design

The SQLite database maintains relational integrity with strict constraints:

sql
CREATE TABLE IF NOT EXISTS students (
    student_id TEXT PRIMARY KEY,
    full_name TEXT NOT NULL,
    department TEXT NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS attendance_logs (
    log_id INTEGER PRIMARY KEY AUTOINCREMENT,
    student_id TEXT NOT NULL,
    session_date DATE NOT NULL,
    scan_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    status TEXT NOT NULL CHECK(status IN ('PRESENT', 'LATE')),
    FOREIGN KEY(student_id) REFERENCES students(student_id),
    UNIQUE(student_id, session_date)
);

Verification & Key Takeaways

  • Performance: OpenCV frame ingestion runs cleanly on modest commodity hardware.
  • Integrity: Enforcing UNIQUE(student_id, session_date) at the SQLite schema level guarantees that concurrent or repeated rapid scans cannot corrupt attendance counts.
  • Future Work: Implementing HMAC-SHA256 time-based rolling tokens in generated QR codes to prevent unauthorized screenshot sharing.
Key features and decisions
  • ›Real-time webcam video stream ingestion at 30 FPS using OpenCV.
  • ›Robust barcode and 2D QR decoding powered by pyzbar (ZBar C library bindings).
  • ›Transactional SQLite database schema with indexes on student IDs and session timestamps.
  • ›Duplicate scan prevention logic enforcing single-record constraints per session window.
  • ›Visual bounding box and decoded metadata overlay rendered directly on the live camera viewport.
Challenges and limitations
  • !Requires adequate ambient lighting and camera focus for high-density QR decoding.
  • !Single-threaded camera loop; long database blocking operations would drop video frames without asynchronous decoupling.
  • !Does not implement cryptographic signatures on QR payloads in the base version, making QR screenshot duplication a known limitation.