最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python opencv人臉識別考勤系統(tǒng)的完整源碼

 更新時間:2021年04月26日 11:59:29   作者:alicema1111  
這篇文章主要介紹了python opencv人臉識別考勤系統(tǒng)的完整源碼,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

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

運行結(jié)果如下:

代碼如下:

import wx
import wx.grid
from time import localtime,strftime
import os
import io
import zlib
import dlib  # 人臉識別的庫dlib
import numpy as np  # 數(shù)據(jù)處理的庫numpy
import cv2  # 圖像處理的庫OpenCv
import _thread
import threading
 
ID_NEW_REGISTER = 160
ID_FINISH_REGISTER = 161
 
ID_START_PUNCHCARD = 190
ID_END_PUNCARD = 191
 
ID_OPEN_LOGCAT = 283
ID_CLOSE_LOGCAT = 284
 
ID_WORKER_UNAVIABLE = -1
 
PATH_FACE = "data/face_img_database/"
# face recognition model, the object maps human faces into 128D vectors
facerec = dlib.face_recognition_model_v1("model/dlib_face_recognition_resnet_model_v1.dat")
# Dlib 預測器
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('model/shape_predictor_68_face_landmarks.dat')
 
class WAS(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self,parent=None,title="員工考勤系統(tǒng)",size=(920,560))
 
        self.initMenu()
        self.initInfoText()
        self.initGallery()
        self.initDatabase()
        self.initData()
 
    def initData(self):
        self.name = ""
        self.id =ID_WORKER_UNAVIABLE
        self.face_feature = ""
        self.pic_num = 0
        self.flag_registed = False
        self.puncard_time = "21:00:00"
        self.loadDataBase(1)
 
    def initMenu(self):
 
        menuBar = wx.MenuBar()  #生成菜單欄
        menu_Font = wx.Font()#Font(faceName="consolas",pointsize=20)
        menu_Font.SetPointSize(14)
        menu_Font.SetWeight(wx.BOLD)
 
 
        registerMenu = wx.Menu() #生成菜單
        self.new_register = wx.MenuItem(registerMenu,ID_NEW_REGISTER,"新建錄入")
        self.new_register.SetBitmap(wx.Bitmap("drawable/new_register.png"))
        self.new_register.SetTextColour("SLATE BLUE")
        self.new_register.SetFont(menu_Font)
        registerMenu.Append(self.new_register)
 
        self.finish_register = wx.MenuItem(registerMenu,ID_FINISH_REGISTER,"完成錄入")
        self.finish_register.SetBitmap(wx.Bitmap("drawable/finish_register.png"))
        self.finish_register.SetTextColour("SLATE BLUE")
        self.finish_register.SetFont(menu_Font)
        self.finish_register.Enable(False)
        registerMenu.Append(self.finish_register)
 
 
        puncardMenu = wx.Menu()
        self.start_punchcard = wx.MenuItem(puncardMenu,ID_START_PUNCHCARD,"開始簽到")
        self.start_punchcard.SetBitmap(wx.Bitmap("drawable/start_punchcard.png"))
        self.start_punchcard.SetTextColour("SLATE BLUE")
        self.start_punchcard.SetFont(menu_Font)
        puncardMenu.Append(self.start_punchcard)
 
 
        self.close_logcat = wx.MenuItem(logcatMenu, ID_CLOSE_LOGCAT, "關(guān)閉日志")
        self.close_logcat.SetBitmap(wx.Bitmap("drawable/close_logcat.png"))
        self.close_logcat.SetFont(menu_Font)
        self.close_logcat.SetTextColour("SLATE BLUE")
        logcatMenu.Append(self.close_logcat)
 
        menuBar.Append(registerMenu,"&人臉錄入")
        menuBar.Append(puncardMenu,"&刷臉簽到")
        menuBar.Append(logcatMenu,"&考勤日志")
        self.SetMenuBar(menuBar)
 
        self.Bind(wx.EVT_MENU,self.OnNewRegisterClicked,id=ID_NEW_REGISTER)
        self.Bind(wx.EVT_MENU,self.OnFinishRegisterClicked,id=ID_FINISH_REGISTER)
        self.Bind(wx.EVT_MENU,self.OnStartPunchCardClicked,id=ID_START_PUNCHCARD)
        self.Bind(wx.EVT_MENU,self.OnEndPunchCardClicked,id=ID_END_PUNCARD)
        self.Bind(wx.EVT_MENU,self.OnOpenLogcatClicked,id=ID_OPEN_LOGCAT)
        self.Bind(wx.EVT_MENU,self.OnCloseLogcatClicked,id=ID_CLOSE_LOGCAT)
 
 
        pass
 
    def OnCloseLogcatClicked(self,event):
        self.SetSize(920,560)
 
        self.initGallery()
        pass
 
    def register_cap(self,event):
        # 創(chuàng)建 cv2 攝像頭對象
        self.cap = cv2.VideoCapture(0)
        # cap.set(propId, value)
        # 設置視頻參數(shù),propId設置的視頻參數(shù),value設置的參數(shù)值
        # self.cap.set(3, 600)
        # self.cap.set(4,600)
        # cap是否初始化成功
        while self.cap.isOpened():
            # cap.read()
            # 返回兩個值:
            #    一個布爾值true/false,用來判斷讀取視頻是否成功/是否到視頻末尾
            #    圖像對象,圖像的三維矩陣
            flag, im_rd = self.cap.read()
 
            # 每幀數(shù)據(jù)延時1ms,延時為0讀取的是靜態(tài)幀
            kk = cv2.waitKey(1)
            # 人臉數(shù) dets
            dets = detector(im_rd, 1)
 
            # 檢測到人臉
            if len(dets) != 0:
                biggest_face = dets[0]
                #取占比最大的臉
                maxArea = 0
                for det in dets:
                    w = det.right() - det.left()
                    h = det.top()-det.bottom()
                    if w*h > maxArea:
                        biggest_face = det
                        maxArea = w*h
                        # 繪制矩形框
 
                cv2.rectangle(im_rd, tuple([biggest_face.left(), biggest_face.top()]),
                                      tuple([biggest_face.right(), biggest_face.bottom()]),
                                      (255, 0, 0), 2)
                img_height, img_width = im_rd.shape[:2]
                image1 = cv2.cvtColor(im_rd, cv2.COLOR_BGR2RGB)
                pic = wx.Bitmap.FromBuffer(img_width, img_height, image1)
                # 顯示圖片在panel上
                self.bmp.SetBitmap(pic)
 
                # 獲取當前捕獲到的圖像的所有人臉的特征,存儲到 features_cap_arr
                shape = predictor(im_rd, biggest_face)
                features_cap = facerec.compute_face_descriptor(im_rd, shape)
 
                # 對于某張人臉,遍歷所有存儲的人臉特征
                for i,knew_face_feature in enumerate(self.knew_face_feature):
                    # 將某張人臉與存儲的所有人臉數(shù)據(jù)進行比對
                    compare = return_euclidean_distance(features_cap, knew_face_feature)
                    if compare == "same":  # 找到了相似臉
                        self.infoText.AppendText(self.getDateAndTime()+"工號:"+str(self.knew_id[i])
                                                 +" 姓名:"+self.knew_name[i]+" 的人臉數(shù)據(jù)已存在\r\n")
                        self.flag_registed = True
                        self.OnFinishRegister()
                        _thread.exit()
 
                        # print(features_known_arr[i][-1])
                face_height = biggest_face.bottom()-biggest_face.top()
                face_width = biggest_face.right()- biggest_face.left()
                im_blank = np.zeros((face_height, face_width, 3), np.uint8)
                try:
                    for ii in range(face_height):
                        for jj in range(face_width):
                            im_blank[ii][jj] = im_rd[biggest_face.top() + ii]parent=self.bmp,max=100000000,min=ID_WORKER_UNAVIABLE)
            for knew_id in self.knew_id:
                if knew_id == self.id:
                    self.id = ID_WORKER_UNAVIABLE
                    wx.MessageBox(message="工號已存在,請重新輸入", caption="警告")
 
        while self.name == '':
            self.name = wx.GetTextFromUser(message="請輸入您的的姓名,用于創(chuàng)建姓名文件夾",
                                           caption="溫馨提示",
                                      default_value="", parent=self.bmp)
 
            # 監(jiān)測是否重名
            for exsit_name in (os.listdir(PATH_FACE)):
                if self.name == exsit_name:
                    wx.MessageBox(message="姓名文件夾已存在,請重新輸入", caption="警告")
                    self.name = ''
                    break
        os.makedirs(PATH_FACE+self.name)
        _thread.start_new_thread(self.register_cap,(event,))
        pass
 
    def OnFinishRegister(self):
 
        self.new_register.Enable(True)
        self.finish_register.Enable(False)
        self.cap.release()
 
        self.bmp.SetBitmap(wx.Bitmap(self.pic_index))
        if self.flag_registed == True:
            dir = PATH_FACE + self.name
            for file in os.listdir(dir):
                os.remove(dir+"/"+file)
                print("已刪除已錄入人臉的圖片", dir+"/"+file)
            os.rmdir(PATH_FACE + self.name)
            print("已刪除已錄入人臉的姓名文件夾", dir)
            self.initData()
            return
        if self.pic_num>0:
            pics = os.listdir(PATH_FACE + self.name)
            feature_list = []
            feature_average = []
            for i in range(len(pics)):
                pic_path = PATH_FACE + self.name + "/" + pics[i]
                print("正在讀的人臉圖像:", pic_path)
                img = iio.imread(pic_path)
                img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
                dets = detector(img_gray, 1)
                if len(dets) != 0:
                    shape = predictor(img_gray, dets[0])
                    face_descriptor = facerec.compute_face_descriptor(img_gray, shape)
                    feature_list.append(face_descriptor)
                else:
                    face_descriptor = 0
                    print("未在照片中識別到人臉")
            if len(feature_list) > 0:
                for j in range(128):
                    #防止越界
                    feature_average.append(0)
                    for i in range(len(feature_list)):
                        feature_average[j] += feature_list[i][j]
                    feature_average[j] = (feature_average[j]) / len(feature_list)
                self.insertARow([self.id,self.name,feature_average],1)
                self.infoText.AppendText(self.getDateAndTime()+"工號:"+str(self.id)
                                     +" 姓名:"+self.name+" 的人臉數(shù)據(jù)已成功存入\r\n")
            pass
 
        else:
            os.rmdir(PATH_FACE + self.name)
            print("已刪除空文件夾",PATH_FACE + self.name)
        self.initData()
 
    def OnFinishRegisterClicked(self,event):
        self.OnFinishRegister()
        pass
 
 
    def OnStartPunchCardClicked(self,event):
        # cur_hour = datetime.datetime.now().hour
        # print(cur_hour)
        # if cur_hour>=8 or cur_hour<6:
        #     wx.MessageBox(message='''您錯過了今天的簽到時間,請明天再來\n
        #     每天的簽到時間是:6:00~7:59''', caption="警告")
        #     return
        self.start_punchcard.Enable(False)
        self.end_puncard.Enable(True)
        self.loadDataBase(2)
        threading.Thread(target=self.punchcard_cap,args=(event,)).start()
        #_thread.start_new_thread(self.punchcard_cap,(event,))
        pass
 
    def OnEndPunchCardClicked(self,event):
        self.start_punchcard.Enable(True)
        self.end_puncard.Enable(False)
        pass
 
 
    def initGallery(self):
        self.pic_index = wx.Image("drawable/index.png", wx.BITMAP_TYPE_ANY).Scale(600, 500)
        self.bmp = wx.StaticBitmap(parent=self, pos=(320,0), bitmap=wx.Bitmap(self.pic_index))
        pass
 
    def getDateAndTime(self):
        dateandtime = strftime("%Y-%m-%d %H:%M:%S",localtime())
        return "["+dateandtime+"]"
 
    #數(shù)據(jù)庫部分
    #初始化數(shù)據(jù)庫
    def initDatabase(self):
        conn = sqlite3.connect("inspurer.db")  #建立數(shù)據(jù)庫連接
        cur = conn.cursor()             #得到游標對象
        cur.execute('''create table if not exists worker_info
        (name text not null,
        id int not null primary key,
        face_feature array not null)''')
        cur.execute('''create table if not exists logcat
         (datetime text not null,
         id int not null,
         name text not null,
         late text not null)''')
        cur.close()
        conn.commit()
        conn.close()
 
    def adapt_array(self,arr):
        out = io.BytesIO()
        np.save(out, arr)
        out.seek(0)
 
        dataa = out.read()
        # 壓縮數(shù)據(jù)流
        return sqlite3.Binary(zlib.compress(dataa, zlib.Z_BEST_COMPRESSION))
 
    def convert_array(self,text):
        out = io.BytesIO(text)
        out.seek(0)
 
        dataa = out.read()
        # 解壓縮數(shù)據(jù)流
        out = io.BytesIO(zlib.decompress(dataa))
        return np.load(out)
 
    def insertARow(self,Row,type):
        conn = sqlite3.connect("inspurer.db")  # 建立數(shù)據(jù)庫連接
        cur = conn.cursor()  # 得到游標對象
        if type == 1:
            cur.execute("insert into worker_info (id,name,face_feature) values(?,?,?)",
                    (Row[0],Row[1],self.adapt_array(Row[2])))
            print("寫人臉數(shù)據(jù)成功")
        if type == 2:
            cur.execute("insert into logcat (id,name,datetime,late) values(?,?,?,?)",
                        (Row[0],Row[1],Row[2],Row[3]))
            print("寫日志成功")
            pass
        cur.close()
        conn.commit()
        conn.close()
        pass
 
    def loadDataBase(self,type):
 
        conn = sqlite3.connect("inspurer.db")  # 建立數(shù)據(jù)庫連接
        cur = conn.cursor()  # 得到游標對象
 
        if type == 1:
            self.knew_id = []
            self.knew_name = []
            self.knew_face_feature = []
            cur.execute('select id,name,face_feature from worker_info')
            origin = cur.fetchall()
            for row in origin:
                print(row[0])
                self.knew_id.append(row[0])
                print(row[1])
                self.knew_name.append(row[1])
                print(self.convert_array(row[2]))
                self.knew_face_feature.append(self.convert_array(row[2]))
        if type == 2:
            self.logcat_id = []
            self.logcat_name = []
            self.logcat_datetime = []
            self.logcat_late = []
            cur.execute('select id,name,datetime,late from logcat')
            origin = cur.fetchall()
            for row in origin:
                print(row[0])
                self.logcat_id.append(row[0])
                print(row[1])
                self.logcat_name.append(row[1])
                print(row[2])
                self.logcat_datetime.append(row[2])
                print(row[3])
                self.logcat_late.append(row[3])
        pass
app = wx.App()
frame = WAS()
frame.Show()
app.MainLoop()

運行結(jié)果如下:

C++學習參考實例

使用C++ MFC編寫一個簡單的五子棋游戲程序

http://www.fzitv.net/article/180940.htm

C++實現(xiàn)簡易五子棋游戲

http://www.fzitv.net/article/190548.htm

c++ 基于opencv 識別、定位二維碼

http://www.fzitv.net/article/207158.htm

到此這篇關(guān)于python opencv人臉識別考勤系統(tǒng)的完整源碼的文章就介紹到這了,更多相關(guān)python 人臉識別考勤系統(tǒng)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 詳解在python操作數(shù)據(jù)庫中游標的使用方法

    詳解在python操作數(shù)據(jù)庫中游標的使用方法

    這篇文章主要介紹了在python操作數(shù)據(jù)庫中游標的使用方法,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-11-11
  • Python實現(xiàn)查找字符串數(shù)組最長公共前綴示例

    Python實現(xiàn)查找字符串數(shù)組最長公共前綴示例

    這篇文章主要介紹了Python實現(xiàn)查找字符串數(shù)組最長公共前綴,涉及Python針對字符串的遍歷、判斷、計算等相關(guān)操作技巧,需要的朋友可以參考下
    2019-03-03
  • Python set集合類型操作總結(jié)

    Python set集合類型操作總結(jié)

    這篇文章主要介紹了Python set集合類型操作總結(jié),本文介紹了一個小技巧、去重技巧、創(chuàng)建set、set基本操作等內(nèi)容,需要的朋友可以參考下
    2014-11-11
  • 如何使用Python控制攝像頭錄制視頻

    如何使用Python控制攝像頭錄制視頻

    這篇文章主要介紹了如何使用Python控制攝像頭錄制視頻,實現(xiàn)過程需要用到三個庫tkinter庫、PIL庫、cv2庫,下面將內(nèi)容詳細的一步一步實現(xiàn),希望對你有所啟發(fā)并能做一個屬于自己的攝像頭控制程序
    2022-03-03
  • Python3 json模塊之編碼解碼方法講解

    Python3 json模塊之編碼解碼方法講解

    這篇文章主要介紹了Python3 json模塊之編碼解碼方法講解,需要的朋友可以參考下
    2021-04-04
  • Python動態(tài)演示旋轉(zhuǎn)矩陣的作用詳解

    Python動態(tài)演示旋轉(zhuǎn)矩陣的作用詳解

    一個矩陣我們想讓它通過編程,實現(xiàn)各種花樣的變化怎么辦呢?下面這篇文章主要給大家介紹了關(guān)于Python動態(tài)演示旋轉(zhuǎn)矩陣的作用,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-12-12
  • Django傳遞數(shù)據(jù)給前端的3種方式小結(jié)

    Django傳遞數(shù)據(jù)給前端的3種方式小結(jié)

    Django從后臺往前臺傳遞數(shù)據(jù)時有多種方法可以實現(xiàn),下面這篇文章主要給大家介紹了關(guān)于Django傳遞數(shù)據(jù)給前端的3種方式,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
    2024-01-01
  • python使用turtle庫寫六角形的思路與代碼

    python使用turtle庫寫六角形的思路與代碼

    學習Python,接觸到turtle包,就用它來畫一下六邊形,下面這篇文章主要給大家介紹了關(guān)于python使用turtle庫寫六角形的思路與代碼,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-11-11
  • Python?字典中鍵映射多個值的問題解決

    Python?字典中鍵映射多個值的問題解決

    本文主要介紹了在Python中實現(xiàn)一個字典multidict中鍵可以對應多個值,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2025-01-01
  • python使用tensorflow保存、加載和使用模型的方法

    python使用tensorflow保存、加載和使用模型的方法

    本篇文章主要介紹了python使用tensorflow保存、加載和使用模型的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01

最新評論

中西区| 谢通门县| 襄垣县| 唐山市| 璧山县| 双城市| 合川市| 光山县| 于都县| 招远市| 天台县| 噶尔县| 达孜县| 苗栗县| 寻甸| 合川市| 遵义市| 苗栗市| 霸州市| 阳高县| 镇江市| 峨眉山市| 荔波县| 黑水县| 内江市| 阜康市| 天峨县| 德昌县| 澳门| 长泰县| 祁连县| 石狮市| 行唐县| 高碑店市| 色达县| 华亭县| 福建省| 肇东市| 东乡| 新兴县| 清新县|