Python-Based Face Recognition Attendance System Using PyQt5, OpenCV, and MySQL
This article introduces a Python 3.6‑based attendance system that combines PyQt5 for the GUI, OpenCV and DeepFace for real‑time face recognition with liveness detection, and MySQL for storing student and class data, detailing its design, database setup, features, and step‑by‑step usage instructions.
The project is a Python 3.6 application that uses Qt Designer to create the graphical interface, PyQt5 for widget functionality, the open‑source DeepFace algorithm for face recognition, blink detection for liveness, and OpenCV3 for real‑time processing. Student information, class sizes, and attendance records are stored in a MySQL database for centralized management.
Frontend Design : The UI is built with Qt Designer, featuring a main window and an information‑collection screen. Screenshots of the layouts are provided in the original article.
Database Access : Navicat is used as a visual tool to manage the MySQL database. The article shows the creation process of the database and tables, and explains that only basic PyMySQL commands (insert, query) are required for interaction.
PyMySQL Usage : Simple code snippets demonstrate how to connect to the database, e.g., db = pymysql.connect("localhost", "root", "mysql105", "facerecognition") , making it easy for developers without deep database knowledge to get started.
System Functions : The system currently supports information collection, face recognition, liveness detection (with a known bug that may cause UI freeze), attendance query, student information query, and leave registration.
Usage Tutorial – Environment Setup :
opencv+contrib
安装步骤:
1. https://www.lfd.uci.edu/~gohlke/pythonlibs/ 搜索contrib
2. 找到对应你系统python版本的opencv+contrib下载
3. 我安装的是:opencv_python-4.1.2+contrib-cp37-cp37m-win_amd64.whl
4. 打开anaconda命令行 pip install opencv_python-4.1.2+contrib-cp37-cp37m-win_amd64.whl
cmake
官网下载.msi安装包 下载即可,安装注意导入系统环境变量
dilib
直接anaconda命令行中 pip install dlib(时间比较长)
freetype
pip install freetype-py
pymysql
pip install pymysql
pyqt5
pip install pyqt5
Modifying Source Code : After installing the MySQL service, edit exacute.py to update the database connection string (e.g., the line shown above). If face images are not captured through the system, place them in face_dataset/XX , where XX is the student’s unique ID.
Step‑by‑Step Usage :
Create the database with Navicat and input student and class information.
Modify the source code to connect to the created database.
Collect face photos via the “Information Collection” interface.
Train the face‑recognition model by clicking “Update Face Library”.
Start attendance by opening the camera and selecting “Start Attendance”.
Enjoy the system!
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.