前言
本專案為IOT實驗室人員簽到考勤設計,系統實作功能:
?人員人臉識別并完成簽到/簽退
?考勤時間計算
?保存考勤資料為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


專案配置


代碼部分
核心代碼
python學習交流Q群:906715085#### 「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)
人臉識別部分
python學習交流Q群:906715085#### ## 人臉識別部分 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格式,安全性較低

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/492239.html
標籤:Python
上一篇:python常用標準庫(壓縮包模塊zipfile和tarfile)
下一篇:Python之B站視頻獲取
