国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Python+Qt人臉識別門禁管理系統(tǒng)

這篇具有很好參考價值的文章主要介紹了Python+Qt人臉識別門禁管理系統(tǒng)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

程序示例精選

Python+Qt人臉識別門禁管理系統(tǒng)

如需安裝運行環(huán)境或遠程調(diào)試,見文章底部個人QQ名片,由專業(yè)技術(shù)人員遠程協(xié)助!

前言

這篇博客針對<<Python+Qt人臉識別門禁管理系統(tǒng)>>編寫代碼,代碼整潔,規(guī)則,易讀。 學(xué)習(xí)與應(yīng)用推薦首選。


文章目錄

一、所需工具軟件

二、使用步驟

????????1. 引入庫

????????2. 代碼實現(xiàn)

???????3. 運行結(jié)果

三、在線協(xié)助

一、所需工具軟件

1. Python

2. Qt, OpenCV

二、使用步驟

1.引入庫

## coding:utf-8
import sys
import os
import csv
import cv2
from untitled import Ui_mainWindow
import record
import name
from dbase import Record2
from PyQt5 import QtWidgets

from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import QPixmap,QPainter

2. 代碼實現(xiàn)

代碼如下:

class myWin(QtWidgets.QMainWindow, Ui_mainWindow):

    def __init__(self):
        super(myWin, self).__init__()
        self.setupUi(self)

        self.pushButton_4.clicked.connect(self.onVideo) #
        self.open_flag = False  #
        self.painter = QPainter(self)  #

        self.pushButton.clicked.connect(self.openFileButton)
        self.pushButton_2.clicked.connect(self.open_name_ui)
        self.pushButton_7.clicked.connect(self.train)
        #self.pushButton_6.clicked.connect(self.faceRecog)
        self.pushButton_3.clicked.connect(self.open_second_ui)

        self.pushButton_5.clicked.connect(self.threadRun)
        self.pushButton_6.clicked.connect(self.switch_video)
        self.timer2 = VideoTimer()
        self.timer2.timeSignal.signal[str].connect(self.videoRecog2)

        self.pushButton_8.clicked.connect(self.recogConform)
        self.pushButton.hide()
        self.pushButton_4.hide()


    def threadRun(self):
        # thread1.start()
        if self.pushButton_5.text() == "模型初始化thread":
            threadSetup()
            # thread1.start()
            self.pushButton_5.setText("停止模型thread")

        elif self.pushButton_5.text() == "停止模型thread":
            # stop_thread(thread1)
            # stop_thread(threadT)
            threadStop()
            print("tttt6")
            self.pushButton_5.setText("模型初始化thread")


    # # 退出系統(tǒng)窗口 X 綁定函數(shù)事件
    def closeEvent(self, event):
        # print("test")
        self.box = QMessageBox(QMessageBox.Warning, "系統(tǒng)提示信息", "是否退出系統(tǒng)?")
        qyes = self.box.addButton(self.tr("是"), QMessageBox.YesRole)
        qno = self.box.addButton(self.tr("否"), QMessageBox.NoRole)
        self.box.exec_()
        if self.box.clickedButton() == qyes:
            try:
                threadStop()
            except:
                print("abnormal")
            event.accept()
            QtWidgets.QWidget.closeEvent(self, event)
            sys.exit().accept()
        else:
            event.ignore()

    def switch_video(self):
        # self.timer2.start()
        if self.pushButton_6.text() == "開始檢測":
            self.timer2.start()
            print("tttt6")
            self.pushButton_6.setText("暫停檢測")
        elif self.pushButton_6.text() == "暫停檢測":
            self.timer2.stop()
            print("tttt6")
            self.pushButton_6.setText("開始檢測")

    def videoRecog2(self):

        # print("im02: ",im02)
        import cv2
        import numpy as np
        count = 0
        recognizer = cv2.face.LBPHFaceRecognizer_create()
        recognizer.read('face_trainer/trainer.yml')
        cascadePath = "haarcascade_frontalface_default.xml"
        faceCascade = cv2.CascadeClassifier(cascadePath)
        font = cv2.FONT_HERSHEY_SIMPLEX
        print("11")



        gray = cv2.cvtColor(im02, cv2.COLOR_BGR2GRAY)
        faces = faceCascade.detectMultiScale(
            gray,
            scaleFactor=1.2,
            minNeighbors=5,

        )

        if len(faces) == 0:
            print("len(faces)", len(faces))

            frame = cv2.cvtColor(im02, cv2.COLOR_BGR2RGB)
            height, width, bytesPerComponent = frame.shape
            bytesPerLine = bytesPerComponent * width

            self.q_image = QtGui.QImage(frame.data, width, height, bytesPerLine, QtGui.QImage.Format_RGB888).scaled(self.label.height() * 1.5, self.label.height())
            self.label.setPixmap(QPixmap.fromImage(self.q_image))
            self.update()  # 

        if len(faces) == 1:
            for (x, y, w, h) in faces:
                idnum, confidence = recognizer.predict(gray[y:y + h, x:x + w])
                print("confidence", confidence)
                print("idnum", idnum)


                # cv2.putText(img, str(username), (x + 5, y - 5), font, 1, (0, 0, 255), 1)
                confidence2 = round(160 - confidence)
                if confidence2 > 80:
                    cv2.rectangle(im02, (x, y), (x + w, y + h), (0, 255, 0), 3)
                    cv2.putText(im02, str(confidence2) + "%", (x + 5, y + h - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5,
                                (37, 46, 6), 1)

                if confidence2 <= 80:
                    cv2.rectangle(im02, (x, y), (x + w, y + h), (255, 0, 0), 3)
                    cv2.putText(im02, "unknow", (x + 5, y + h - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5,
                                (37, 46, 6), 1)

                frame = cv2.cvtColor(im02, cv2.COLOR_BGR2RGB)
                height, width, bytesPerComponent = frame.shape
                bytesPerLine = bytesPerComponent * width

                self.q_image = QtGui.QImage(frame.data, width, height, bytesPerLine, QtGui.QImage.Format_RGB888) \
                    .scaled(self.label.height() * 1.5, self.label.height())
                self.label.setPixmap(QPixmap.fromImage(self.q_image))
                self.update()  # 

            if confidence2 > 80:
                print("confidence2", confidence2)
                global usernamedb
                global chinese_name
                global idnumberNum


                import dbase
                import sqlite3
                import datetime
                from datetime import datetime
                conn = sqlite3.connect("recordinfo.db", check_same_thread=False)
                curr = conn.cursor()
                curr.execute("select idnumber from name_table")
                # curr.execute('insert into name_table values (null, ?)', [name])
                results = curr.fetchall()
                name_list = []
                for i in results:
                    i = list(i)
                    name_list += i
                print("name_list", name_list)
                print("idnum", idnum)
                usernamedb = name_list[idnum]
                print("usernamedb", usernamedb)

                curr.execute("select chinese_name from name_table")
                results2 = curr.fetchall()
                name_list2 = []
                for i in results2:
                    i = list(i)
                    name_list2 += i
                print(name_list2)
                CHusernamedb = name_list2[idnum]
                print("CHusernamedb", CHusernamedb)
                chinese_name = CHusernamedb
                result = 'Ok'

                curr.execute("select idnumber from name_table")
                results3 = curr.fetchall()
                name_list3 = []
                for i in results3:
                    i = list(i)
                    name_list3 += i
                print(name_list3)
                idnumber = name_list3[idnum]
                print("idnumber", idnumber)
                idnumberNum = idnumber

                # curr.execute('insert into record_table values (null, ?, ?, ?,?,?)',
                #              (usernamedb, datetime.now(), chinese_name, 'Ok', idnumberNum))
                conn.commit()
                conn.rollback()
                curr.close()
                conn.close()

                self.textEdit.setPlainText("姓名" + ' ' + chinese_name + ' ' + "識別成功,門已打開")

                #self.recogConform() #模擬開門暫時不保存識別數(shù)據(jù)到數(shù)據(jù)庫,以免人沒離開攝像頭重復(fù)保存多的數(shù)據(jù)到數(shù)據(jù)庫,暫時用界面上識別手動確認保存識別信息到數(shù)據(jù)庫

                # msg_box = QMessageBox(QMessageBox.Warning, '信息', '人臉識別成功')
                # msg_box.exec_()




        # frame = cv2.cvtColor(im02, cv2.COLOR_BGR2RGB)
        # height, width, bytesPerComponent = frame.shape
        # bytesPerLine = bytesPerComponent * width
        #
        # self.q_image = QtGui.QImage(frame.data, width, height, bytesPerLine, QtGui.QImage.Format_RGB888) \
        #     .scaled(self.label.height() * 0.8, self.label.height() * 0.6)
        # self.label.setPixmap(QPixmap.fromImage(self.q_image))
        # self.update()

    def recogConform(self):
        global usernamedb
        global chinese_name
        global idnumberNum

        import dbase
        import sqlite3
        import datetime
        from datetime import datetime
        conn = sqlite3.connect("recordinfo.db", check_same_thread=False)
        curr = conn.cursor()
        curr.execute('insert into record_table values (null, ?, ?, ?,?,?)',
                     (usernamedb, datetime.now(), chinese_name, 'Ok', idnumberNum))

        conn.commit()
        conn.rollback()
        curr.close()
        conn.close()

        self.textEdit.append("識別保存成功")

        # msg_box = QMessageBox(QMessageBox.Warning, '信息', '識別保存成功')
        # msg_box.exec_()

    def openFileButton(self):
        #imgName, imgType  = QFileDialog.getOpenFileName(self,"打開文件","./","files(*.*)")
        self.cap = cv2.VideoCapture(0)
        self.pushButton_4.clicked.connect(self.onVideo) #
        self.open_flag = True  #
        self.painter = QPainter(self)  #
    def onVideo(self):
        print("self.open_flag: ", self.open_flag)
        if self.open_flag:
            self.pushButton_4.setText('Open')
            print("change1")
        else:
            self.pushButton_4.setText('Close')
            print("change2")
        self.open_flag = bool(1-self.open_flag)
        print("change3")

3. 運行結(jié)果

Python+Qt人臉識別門禁管理系統(tǒng)

?

三、在線協(xié)助:

如需安裝運行環(huán)境或遠程調(diào)試,見文章底部個人 QQ 名片,由專業(yè)技術(shù)人員遠程協(xié)助!
1)遠程安裝運行環(huán)境,代碼調(diào)試
2)Qt, C++, Python入門指導(dǎo)
3)界面美化
4)軟件制作

博主推薦文章:python人臉識別統(tǒng)計人數(shù)qt窗體-CSDN博客

博主推薦文章:Python Yolov5火焰煙霧識別源碼分享-CSDN博客

? ? ? ? ? ? ? ? ? ? ? ? ?Python OpenCV識別行人入口進出人數(shù)統(tǒng)計_python識別人數(shù)-CSDN博客

個人博客主頁:alicema1111的博客_CSDN博客-Python,C++,網(wǎng)頁領(lǐng)域博主

博主所有文章點這里:alicema1111的博客_CSDN博客-Python,C++,網(wǎng)頁領(lǐng)域博主文章來源地址http://www.zghlxwxcb.cn/news/detail-424761.html

到了這里,關(guān)于Python+Qt人臉識別門禁管理系統(tǒng)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包