日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

Python人脸识别考勤打卡系统

發(fā)布時(shí)間:2023/12/31 windows 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python人脸识别考勤打卡系统 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Python人臉識(shí)別考勤打卡系統(tǒng)

如需安裝運(yùn)行環(huán)境或遠(yuǎn)程調(diào)試,可加QQ905733049,?或QQ2945218359由專業(yè)技術(shù)人員遠(yuǎn)程協(xié)助!

運(yùn)行結(jié)果如下:

?主要代碼:

import random import cv2 import numpy import datetime import os import time import cv2 as cv import numpy as np import threading from PIL import Image, ImageFont, ImageDrawdatabase_file_path = './resources/data.db' picture_dir_path = "./resources/pictures" trainer_file_path = './resources/Trainer/trainer.yml' font_file_path = './resources/simsun.ttc' zsc_circle_file_path = './resources/zsc.jpg' zsc_rectangle_file_path = './resources/zsc.png' haarcascade_frontalface_file_path = './resources/haarcascade_frontalface_default.xml' capture_opt = 0 # 攝像頭參數(shù),0,1為本機(jī)攝像頭# 繼承wx庫(kù)里面的Frame類來(lái)使用 class MainFrame(wx.Frame):def __init__(self):# 初始化窗體數(shù)據(jù)wx.Frame.__init__(self, None, -1, '人臉識(shí)別考勤系統(tǒng)', pos=(100, 100), size=(1337, 600))panel = wx.Panel(self, -1)sizer = wx.BoxSizer(wx.HORIZONTAL)sizer1 = wx.BoxSizer(wx.VERTICAL)sizer2 = wx.BoxSizer(wx.VERTICAL)font = wx.Font(15, wx.ROMAN, wx.NORMAL, wx.BOLD)# 設(shè)置窗口以及托盤圖標(biāo)icon = wx.Icon()icon.CopyFromBitmap(wx.Bitmap(wx.Image((zsc_circle_file_path), wx.BITMAP_TYPE_JPEG)))self.SetIcon(icon)# 設(shè)置左邊背景學(xué)院logoimage = wx.Image(zsc_rectangle_file_path, wx.BITMAP_TYPE_PNG).ConvertToBitmap()self.background = wx.StaticBitmap(panel, -1, bitmap=image, style=wx.ALIGN_CENTER)sizer1.Add(self.background, proportion=10, flag=wx.ALIGN_CENTER, border=10)# 設(shè)置采集人臉按鈕self.command1 = wx.Button(panel, -1, '采集人臉')self.command1.SetFont(font)self.command1.SetBackgroundColour('#3299CC')sizer1.Add(self.command1, proportion=5, flag=wx.ALL | wx.EXPAND, border=10)# 設(shè)置訓(xùn)練數(shù)據(jù)按鈕self.command2 = wx.Button(panel, -1, '訓(xùn)練數(shù)據(jù)')self.command2.SetFont(font)self.command2.SetBackgroundColour('#DBDB70')sizer1.Add(self.command2, proportion=5, flag=wx.ALL | wx.EXPAND, border=10)# 設(shè)置人臉識(shí)別按鈕self.command3 = wx.Button(panel, -1, '識(shí)別打卡')self.command3.SetFont(font)self.command3.SetBackgroundColour('#32CC32')sizer1.Add(self.command3, proportion=5, flag=wx.ALL | wx.EXPAND, border=10)# 設(shè)置退出系統(tǒng)按鈕self.command4 = wx.Button(panel, -1, '關(guān)閉攝像頭')self.command4.SetFont(font)self.command4.SetBackgroundColour((random.randint(1, 255), random.randint(0, 255), random.randint(0, 255)))sizer1.Add(self.command4, proportion=5, flag=wx.ALL | wx.EXPAND, border=10)# 設(shè)置消息提示文本self.text5 = wx.StaticText(panel, -1, '\n\n', style=wx.ALIGN_CENTER)self.text5.SetFont(font)self.text5.SetForegroundColour('Red')sizer1.Add(self.text5, proportion=15, flag=wx.ALL | wx.EXPAND, border=10)# 設(shè)置個(gè)人信息文本self.text6 = wx.StaticText(panel, -1, '姓名:')self.text7 = wx.StaticText(panel, -1, '學(xué)號(hào):')self.text8 = wx.StaticText(panel, -1, '學(xué)院:')sizer1.Add(self.text6, proportion=3, flag=wx.LEFT, border=0)sizer1.Add(self.text7, proportion=3, flag=wx.LEFT, border=0)sizer1.Add(self.text8, proportion=3, flag=wx.LEFT, border=0)# 把分布局全部加入整體頂級(jí)布局sizer.Add(sizer1, flag=wx.EXPAND | wx.ALL, border=20)# 設(shè)置右上邊消息提示文本sizer3 = wx.BoxSizer(wx.HORIZONTAL)font = wx.Font(12, wx.ROMAN, wx.NORMAL, wx.BOLD)self.text9 = wx.StaticText(panel, -1, '', style=wx.ALIGN_LEFT)self.text9.SetFont(font)self.text9.SetForegroundColour('brown')self.text9.SetLabel(u''+'您好,歡迎使用人臉考勤系統(tǒng)!')self.text10 = wx.StaticText(panel, -1, '', style=wx.ALIGN_RIGHT)self.text10.SetFont(font)self.text10.SetForegroundColour('Blue')self.data_num = 0self.updateSumData()sizer3.Add(self.text9, proportion=1, flag= wx.ALL|wx.EXPAND, border=10)sizer3.Add(self.text10, proportion=1, flag= wx.ALL|wx.EXPAND, border=10)sizer2.Add(sizer3, proportion=1, flag=wx.EXPAND | wx.ALL, border=0)# 封面圖片self.image_cover = wx.Image(zsc_circle_file_path, wx.BITMAP_TYPE_ANY).Scale(575, 460)self.bmp = wx.StaticBitmap(panel, -1, wx.Bitmap(self.image_cover))sizer2.Add(self.bmp, proportion=1, flag=wx.ALL|wx.EXPAND ,border=0)# 加入頂級(jí)布局sizer.Add(sizer2, flag=wx.EXPAND | wx.ALL, border=10)# 實(shí)例化數(shù)據(jù)庫(kù)操作對(duì)象self.mySqlDao = MySQLDao(self)self.grid = MyGrid(panel, self.mySqlDao)self.grid.updateGrid()# 打卡記錄表sizer.Add(self.grid, proportion=1, flag=wx.EXPAND | wx.ALL, border=10)panel.SetSizer(sizer)# 四個(gè)按鈕對(duì)應(yīng)的事件self.command1.Bind(wx.EVT_BUTTON, self.command1_event)self.command4.Bind(wx.EVT_BUTTON, self.command4_event)self.command3.Bind(wx.EVT_BUTTON, self.command3_event)self.command2.Bind(wx.EVT_BUTTON, self.command2_event)# 關(guān)閉事件self.Bind(wx.EVT_CLOSE,self.onClose)# 窗口居中,顯示self.Center()self.Show()# 控制攝像頭的開啟與關(guān)閉self.recognition = Falseself.collected = False'''主窗體關(guān)閉事件'''def onClose(self,event):self.command4_event(event)# 等待子線程完成 再關(guān)閉,防止不正常退出time.sleep(1)self.Destroy()'''采集數(shù)據(jù)按鈕的響應(yīng)事件'''def command1_event(self, event):self.text6.SetLabel('姓名:')self.text7.SetLabel('學(xué)號(hào):')self.text8.SetLabel('學(xué)院:')self.text5.SetLabel(u'\n溫馨提示:\n' + '?正在進(jìn)學(xué)生信息錄入...')self.text5.Update()collectFrame = CollectFrame(self,self.mySqlDao)collectFrame.Show()'''訓(xùn)練數(shù)據(jù)按鈕的響應(yīng)事件'''def command2_event(self, event):self.trainData()'''識(shí)別打卡按鈕的響應(yīng)事件'''def command3_event(self, event):self.text5.SetLabel(u'')self.recognition = Falset1 = threading.Thread(target=self.recognitionFace)t1.start()'''關(guān)閉攝像頭按鈕的響應(yīng)事件'''def command4_event(self, event):if self.collected == False:self.collected = Trueif self.recognition == False:self.recognition = Truedef updateSumData(self):self.data_num = 0for list in os.listdir(picture_dir_path):if len(os.listdir(picture_dir_path + '/' + list)) >= 200:self.data_num += 1self.text10.SetLabel(u'當(dāng)前已采集人臉數(shù)據(jù)的人數(shù):' + str(self.data_num))self.text10.Update()'''@Author:Himit_ZH@Function:處理收集人臉每一幀生成圖片存入對(duì)應(yīng)文件夾'''def collect(self,face_id):self.text5.SetLabel(u'\n溫馨提示:\n' + '請(qǐng)看向攝像頭\n準(zhǔn)備采集200張人臉圖片...')count = 0 # 統(tǒng)計(jì)照片數(shù)量path = picture_dir_path+"/Stu_" + str(face_id) # 人臉圖片數(shù)據(jù)的儲(chǔ)存路徑# 讀取視頻cap = cv.VideoCapture(capture_opt)print(cap.isOpened())if cap.isOpened() == False:self.text5.SetLabel(u'\n錯(cuò)誤提示:\n' + '×采集人臉數(shù)據(jù)失敗!\n原因:未能成功打開攝像頭')return# 加載特征數(shù)據(jù)face_detector = cv.CascadeClassifier(haarcascade_frontalface_file_path)if not os.path.exists(path): # 如果沒有對(duì)應(yīng)文件夾,自動(dòng)生成os.makedirs(path)while self.collected == False:flag, frame = cap.read()# print('flag:',flag,'frame.shape:',frame.shape)if not flag:break# 將圖片灰度gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)faces = face_detector.detectMultiScale(gray, 1.1, 3)if len(faces) > 1: # 一幀出現(xiàn)兩張照片丟棄,原因:有人亂入,也有可能人臉識(shí)別出現(xiàn)差錯(cuò)continue# 框選人臉,for循環(huán)保證一個(gè)能檢測(cè)的實(shí)時(shí)動(dòng)態(tài)視頻流for x, y, w, h in faces:cv.rectangle(frame, (x, y), (x + w, y + h), color=(0, 255, 0), thickness=2)count += 1cv.imwrite(path + '/' + str(count) + '.png', gray[y:y + h, x:x + w])# # 顯示圖片# cv.imshow('Camera', frame)# 將一幀幀圖片顯示在UI中image1 = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)image2 = cv2.resize(image1, (575, 460))height, width = image2.shape[:2]pic = wx.Bitmap.FromBuffer(width, height, image2)# 顯示圖片在panel上self.bmp.SetBitmap(pic)self.bmp.Update()self.text9.SetLabel(u'溫馨提示:\n' + '已采集'+ str(count)+'張人臉照片')if count >= 200: #默認(rèn)采集200張照片break# 關(guān)閉資源if count >=200:self.text5.SetLabel(u'\n溫馨提示:\n' + '?已成功采集到人臉數(shù)據(jù)!')self.updateSumData()else:self.text5.SetLabel(u'\n錯(cuò)誤提示:\n' + '×采集人臉數(shù)據(jù)失敗!\n未能收集到200張人臉數(shù)據(jù)!')# 刪除該文件夾下的所有數(shù)據(jù)ls = os.listdir(path)for file_path in ls:f_path = os.path.join(path, file_path)os.remove(f_path)os.rmdir(path)cv.destroyAllWindows()cap.release()self.bmp.SetBitmap(wx.Bitmap(self.image_cover))'''@Author:Himit_ZH@Function:遍歷指定文件夾里面的人臉數(shù)據(jù),根據(jù)文件夾名字,訓(xùn)練對(duì)應(yīng)數(shù)據(jù)'''def trainData(self):self.text5.SetLabel(u'\n溫馨提示:\n' + '?正在整合訓(xùn)練的人臉數(shù)據(jù)\n請(qǐng)稍后...')# 圖片路徑path = picture_dir_pathfacesSamples = []imageFiles = []ids = []for root, dirs, files in os.walk(path):# root 表示當(dāng)前正在訪問(wèn)的文件夾路徑# dirs 表示該文件夾下的子目錄名list# files 表示該文件夾下的文件list# 遍歷文件for file in files:imageFiles.append(os.path.join(root, file))# 檢測(cè)人臉的模型數(shù)據(jù)face_detector = cv2.CascadeClassifier(haarcascade_frontalface_file_path)# 遍歷列表中的圖片stu_map = self.mySqlDao.getIdfromSql()for imagefile in imageFiles: # 獲得所有文件名字imagefile = imagefile.replace('\\', '/')sno = imagefile.split('/')[3].split('_')[1]if stu_map.get(sno):PIL_img = Image.open(imagefile).convert('L') # 打開圖片并且轉(zhuǎn)為灰度圖片# 將圖像轉(zhuǎn)換為數(shù)組img_numpy = np.array(PIL_img, 'uint8')faces = face_detector.detectMultiScale(img_numpy)for x, y, w, h in faces:facesSamples.append(img_numpy[y:y + h, x:x + w])ids.append(int(stu_map.get(sno)))if __name__ == '__main__':app = wx.App()app.locale = wx.Locale(wx.LANGUAGE_CHINESE_SIMPLIFIED)frame = MainFrame()app.MainLoop()

?運(yùn)行結(jié)果如下:

?

Python, C++, PHP語(yǔ)言學(xué)習(xí)參考實(shí)例連接

C++學(xué)習(xí)參考實(shí)例

C++實(shí)現(xiàn)圖形界面五子棋游戲源碼:

https://blog.csdn.net/alicema1111/article/details/90035420

C++實(shí)現(xiàn)圖形界面五子棋游戲源碼2:

https://blog.csdn.net/alicema1111/article/details/106479579

C++ OpenCV相片視頻人臉識(shí)別統(tǒng)計(jì)人數(shù):

https://blog.csdn.net/alicema1111/article/details/105833928

VS2017+PCL開發(fā)環(huán)境配置:

https://blog.csdn.net/alicema1111/article/details/106877145

VS2017+Qt+PCL點(diǎn)云開發(fā)環(huán)境配置:

https://blog.csdn.net/alicema1111/article/details/105433636

C++ OpenCV汽車檢測(cè)障礙物與測(cè)距:

https://blog.csdn.net/alicema1111/article/details/105833449

Windows VS2017安裝配置PCL點(diǎn)云庫(kù):

https://blog.csdn.net/alicema1111/article/details/105111110

VS+VTK+Dicom(dcm)+CT影像切片窗體界面顯示源碼

https://blog.csdn.net/alicema1111/article/details/106994839

Python學(xué)習(xí)參考實(shí)例

Python相片更換背景顏色qt窗體程序:

https://blog.csdn.net/alicema1111/article/details/106919140

OpenCV汽車識(shí)別檢測(cè)數(shù)量統(tǒng)計(jì):

https://blog.csdn.net/alicema1111/article/details/106597260

OpenCV視頻識(shí)別檢測(cè)人數(shù)跟蹤統(tǒng)計(jì):

https://blog.csdn.net/alicema1111/article/details/106113042

OpenCV米粒檢測(cè)數(shù)量統(tǒng)計(jì):

https://blog.csdn.net/alicema1111/article/details/106089697

opencv人臉識(shí)別與變形哈哈鏡:

https://blog.csdn.net/alicema1111/article/details/105833123

OpenCV人臉檢測(cè)打卡系統(tǒng):

https://blog.csdn.net/alicema1111/article/details/105315066

Python+OpenCV攝像頭人臉識(shí)別:

https://blog.csdn.net/alicema1111/article/details/105107286

Python+Opencv識(shí)別視頻統(tǒng)計(jì)人數(shù):

https://blog.csdn.net/alicema1111/article/details/103804032

Python+OpenCV圖像人臉識(shí)別人數(shù)統(tǒng)計(jì)

https://blog.csdn.net/alicema1111/article/details/105378639

python人臉頭發(fā)身體部位識(shí)別人數(shù)統(tǒng)計(jì)

https://blog.csdn.net/alicema1111/article/details/116424942

VS+QT+VTK三維網(wǎng)格圖像顯示GUI

https://blog.csdn.net/alicema1111/article/details/117060734

PHP網(wǎng)頁(yè)框架

PHP Laravel框架安裝與配置后臺(tái)管理前臺(tái)頁(yè)面顯示:

https://blog.csdn.net/alicema1111/article/details/106686523

總結(jié)

以上是生活随笔為你收集整理的Python人脸识别考勤打卡系统的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。