Python+OpenCV人脸识别签到考勤系统实现(附demo)
作者:BIGBOSSyifi 发布时间:2022-01-25 14:05:50
前言
本项目为IOT实验室人员签到考勤设计,系统实现功能:
1.人员人脸识别并完成签到/签退
2.考勤时间计算
3.保存考勤数据为CSV格式(Excel表格)
PS:本系统2D人脸识别,节约了繁琐的人脸识别训练部分,简洁快捷
该项目为测试版,正式版会加入更多的功能,持续更新中…
测试版项目地址我会放到结尾
项目效果图
系统初始化登陆界面
主界面展示图:
签到功能展示
签退功能展示
后台签到数据记录
是否签到/退判断
项目需要的环境
核心环境:
OpenCV-Python 4.5.5.64
face_recognition 1.30
face_recognition_model 0.3.0
dlib 19.23.1
UI窗体界面:
PyQt5 5.15.4
pyqt5-plugins 5.15.4.2.2
PyQt5-Qt5 5.15.2
PyQt5-sip 12.10.1
pyqt5-tools 5.15.4.3.2
编译器
Pycham 2021.1.3
Python版本 3.9.12
Anaconda
辅助开发QT-designer
项目配置
代码部分
核心代码
MainWindow.py
UI文件加载:
class Ui_Dialog(QDialog):
def __init__(self):
super(Ui_Dialog, self).__init__()
loadUi("mainwindow.ui", self) #加载QTUI文件
self.runButton.clicked.connect(self.runSlot)
self._new_window = None
self.Videocapture_ = None
摄像头调用:
def refreshAll(self):
print("当前调用人俩检测摄像头编号(0为笔记本内置摄像头,1为USB外置摄像头):")
self.Videocapture_ = "0"
OutWindow.py
获取当前系统时间
class Ui_OutputDialog(QDialog):
def __init__(self):
super(Ui_OutputDialog, self).__init__()
loadUi("./outputwindow.ui", self) #加载输出窗体UI
#datetime 时间模块
now = QDate.currentDate()
current_date = now.toString('ddd dd MMMM yyyy') #时间格式
current_time = datetime.datetime.now().strftime("%I:%M %p")
self.Date_Label.setText(current_date)
self.Time_Label.setText(current_time)
self.image = None
签到时间计算
def ElapseList(self,name):
with open('Attendance.csv', "r") as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 2
Time1 = datetime.datetime.now()
Time2 = datetime.datetime.now()
for row in csv_reader:
for field in row:
if field in row:
if field == 'Clock In':
if row[0] == name:
Time1 = (datetime.datetime.strptime(row[1], '%y/%m/%d %H:%M:%S'))
self.TimeList1.append(Time1)
if field == 'Clock Out':
if row[0] == name:
Time2 = (datetime.datetime.strptime(row[1], '%y/%m/%d %H:%M:%S'))
self.TimeList2.append(Time2)
人脸识别部分
# 人脸识别部分
faces_cur_frame = face_recognition.face_locations(frame)
encodes_cur_frame = face_recognition.face_encodings(frame, faces_cur_frame)
for encodeFace, faceLoc in zip(encodes_cur_frame, faces_cur_frame):
match = face_recognition.compare_faces(encode_list_known, encodeFace, tolerance=0.50)
face_dis = face_recognition.face_distance(encode_list_known, encodeFace)
name = "unknown" #未知人脸识别为unknown
best_match_index = np.argmin(face_dis)
if match[best_match_index]:
name = class_names[best_match_index].upper()
y1, x2, y2, x1 = faceLoc
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.rectangle(frame, (x1, y2 - 20), (x2, y2), (0, 255, 0), cv2.FILLED)
cv2.putText(frame, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 0.5, (255, 255, 255), 1)
mark_attendance(name)
return frame
签到数据保存与判断
# csv表格保存数据
def mark_attendance(name):
"""
:param name: 人脸识别部分
:return:
"""
if self.ClockInButton.isChecked():
self.ClockInButton.setEnabled(False)
with open('Attendance.csv', 'a') as f:
if (name != 'unknown'): #签到判断:是否为已经识别人脸
buttonReply = QMessageBox.question(self, '欢迎 ' + name, '开始签到' ,
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if buttonReply == QMessageBox.Yes:
date_time_string = datetime.datetime.now().strftime("%y/%m/%d %H:%M:%S")
f.writelines(f'\n{name},{date_time_string},Clock In')
self.ClockInButton.setChecked(False)
self.NameLabel.setText(name)
self.StatusLabel.setText('签到')
self.HoursLabel.setText('开始签到计时中')
self.MinLabel.setText('')
self.Time1 = datetime.datetime.now()
self.ClockInButton.setEnabled(True)
else:
print('签到操作失败')
self.ClockInButton.setEnabled(True)
elif self.ClockOutButton.isChecked():
self.ClockOutButton.setEnabled(False)
with open('Attendance.csv', 'a') as f:
if (name != 'unknown'):
buttonReply = QMessageBox.question(self, '嗨呀 ' + name, '确认签退?',
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if buttonReply == QMessageBox.Yes:
date_time_string = datetime.datetime.now().strftime("%y/%m/%d %H:%M:%S")
f.writelines(f'\n{name},{date_time_string},Clock Out')
self.ClockOutButton.setChecked(False)
self.NameLabel.setText(name)
self.StatusLabel.setText('签退')
self.Time2 = datetime.datetime.now()
self.ElapseList(name)
self.TimeList2.append(datetime.datetime.now())
CheckInTime = self.TimeList1[-1]
CheckOutTime = self.TimeList2[-1]
self.ElapseHours = (CheckOutTime - CheckInTime)
self.MinLabel.setText("{:.0f}".format(abs(self.ElapseHours.total_seconds() / 60)%60) + 'm')
self.HoursLabel.setText("{:.0f}".format(abs(self.ElapseHours.total_seconds() / 60**2)) + 'h')
self.ClockOutButton.setEnabled(True)
else:
print('签退操作失败')
self.ClockOutButton.setEnabled(True)
项目目录结构
后记
因为本系统没有进行人脸训练建立模型,系统误识别率较高,安全性较低
系统优化较差,摄像头捕捉帧数较低(8-9),后台占有高,CPU利用率较高
数据保存CSV格式,安全性较低
正式版改进
1.加入TensorFlow深度学习,提高系统人脸识别安全性与准确性
2.加入MySQL数据库,对签到数据进行更安全保护,不易被修改
3.美化优化UI设计
项目下载
IOT人脸识别签到系统测试版V0.99
来源:https://blog.csdn.net/weixin_50679163/article/details/124310679


猜你喜欢
- 根据题意理解:本质就是写分页查询:每页条数:10条;当前页码:4页;//第一种:select * from (select ROW
- 0 程序环境与所学函数本章程序运行需要导入下面三个库,并定义了一个显示图像的函数所学函数##放大、缩小cv.resize(img,dsize
- 问:我想问一下我在重新装完系统以后装SQL Server2000时提示:以前某个程序安装已在计算机上创建挂起的文件操作,运行安装
- 我就废话不多说了,直接上代码吧!# coding:utf-8 2import turtle as t 3import random 4# 画
- 配置文件是每个项目最基础的部分,也是不可或缺的部分,比如:数据库连接、中间件属性等常见的配置。提前准备appsettings.json 文件
- 一、应用场景为了避免反复的手手工从后台数据库导出某些数据表到Excel文件、高效率到多份离线数据。二、功能事项支持一次性导出多个数据源表、自
- Sql代码 select count(*) from user_objects where object_name=upper(p_tabl
- Python 中有 while 和 for 两种循环机制,其中 while 循环
- 目录1. 解题思路2. 具体解析实现3. 单元测试用例:有一段sql语句,我们需要从中截取出所有字段部分,以便进行后续的类型推断或者别名字段
- ajax缓存和编码问题不难解决,下面是解决方法。编码问题默认使用UTF-8,如果一旦发现对象找不到的情况,可能js中输入了中文,同时js的编
- 1 InnoDB页的概念InnoDB是一个将表中的数据存储在磁盘上的存储引擎,即使我们关闭并重启服务器,数据还是存在。而真正处理数据的过程发
- 我们知道,C++和python各有优缺点,C++可以直接映射到硬件底层,实现高效运行,而python能够方便地来进行编程,有助于工程的快速实
- 前言Tkinter是python内置的标准GUI库,基于Tkinter实现了简易人员管理系统,所用数据库为Mongodb代码时间宝贵!直接上
- 注意这里提取到的人脸图片的保存地址要改成自己要保存的地址opencv人脸的检测模型的路径也要更改为自己安装的opencv的人脸检测模型的路径
- 方法一:torch.nn.DataParallel1. 原理如下图所示:小朋友一个人做4份作业,假设1份需要60min,共需要240min。
- /// <summary> /// 获得目标
- 前言前段时间想实现一个短信验证码的功能,但是卡了很长时间。首先我用的是阿里云的短信服务业务,其首次接入流程如下:在阿里云上开通短信服务后需要
- 本文实例讲述了JavaScript命令模式原理与用法。分享给大家供大家参考,具体如下:第一,命令模式: (1)用于消除调用者和接收者之间直接
- 本文实例讲述了JavaScript中filter的用法。分享给大家供大家参考,具体如下:filterfilter也是一个常用的操作,它用于把
- 然后我们在Interactive Python prompt中测试了一下:>>> import subprocess &n