Python+Qt人脸识别职工录入管理系统

简介: 这篇博客针对<<Python+Qt人脸识别职工录入管理系统>>编写代码,代码整洁,规则,易读。 学习与应用推荐首选。

程序示例精选

Python+Qt人脸识别职工录入管理系统

如需安装运行环境或远程调试,可点击右边主头像昵称进入个人主页查看博主联系方式,由专业技术人员远程协助!

前言

这篇博客针对<<Python+Qt人脸识别职工录入管理系统>>编写代码,代码整洁,规则,易读。 学习与应用推荐首选。


文章目录

一、所需工具软件

二、使用步骤

       1. 引入库

       2. 代码实现

      3. 运行结果

三、在线协助

一、所需工具软件

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 *

image.gif

2. 代码实现

代码如下:

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")
    def closeEvent2(self, event):
        self.box = QMessageBox(QMessageBox.Warning, "系统提示信息", "是否暂停摄像头?")
        qyes = self.box.addButton(self.tr("是"), QMessageBox.YesRole)
        qno = self.box.addButton(self.tr("否"), QMessageBox.NoRole)
        self.box.exec_()
        if self.box.clickedButton() == qyes:
            self.label.clear()
            while 1:
                if cv2.waitKey(1) == ord('q'):
                    break
            self.cap.release()
            cv2.destroyAllWindows()
        else:
            event.ignore()
    def closethreed(self):
        print("test")
    # # 退出系统窗口 X 绑定函数事件
    def closeEvent(self, event):
        # print("test")
        self.box = QMessageBox(QMessageBox.Warning, "系统提示信息", "是否退出系统?")
        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()

image.gif

3. 运行结果

image.gif


三、在线协助:

如需安装运行环境或远程调试, 可点击右边 主头像 昵称 进入个人主页查看博主联系方式 ,由专业技术人员远程协助! 1)远程安装运行环境,代码调试
2)Qt, C++, Python入门指导 3)界面美化
4)软件制作


博主推荐文章:python人脸识别统计人数qt窗体-CSDN博客

博主推荐文章:Python Yolov5火焰烟雾识别源码分享-CSDN博客

                        Python OpenCV识别行人入口进出人数统计_python识别人数-CSDN博客

个人博客主页:alicema1111的博客_CSDN博客-Python,C++,网页领域博主

博主所有文章点这里:alicema1111的博客_CSDN博客-Python,C++,网页领域博主


相关文章
|
1月前
|
存储 人工智能 搜索推荐
【python】python用户管理系统[简易版](源码+报告)【独一无二】
【python】python用户管理系统[简易版](源码+报告)【独一无二】
|
13天前
|
机器学习/深度学习 存储 监控
数据分享|Python卷积神经网络CNN身份识别图像处理在疫情防控下口罩识别、人脸识别
数据分享|Python卷积神经网络CNN身份识别图像处理在疫情防控下口罩识别、人脸识别
|
22小时前
|
前端开发 UED Python
Wagtail-基于Python Django的内容管理系统CMS实现公网访问
Wagtail-基于Python Django的内容管理系统CMS实现公网访问
|
15天前
|
存储 Python
Python 基于列表实现的通讯录管理系统(有完整源码)
Python 基于列表实现的通讯录管理系统(有完整源码)
11 0
|
22天前
|
Python
python 文件操作和学生管理系统练习
python 文件操作和学生管理系统练习
22 0
|
28天前
|
JavaScript 前端开发 API
用Python和Vue构建内容管理系统(CMS):一步步指南
【4月更文挑战第10天】本文介绍了如何使用Python的Django框架和前端的Vue.js构建内容管理系统(CMS)。Django提供后端支持,遵循MTV模式,Vue.js则用于创建数据驱动的用户界面。步骤包括环境准备、Django项目与应用创建、定义数据模型、创建API接口、搭建Vue项目、集成Django与Vue、性能优化及部署上线。这种结合充分利用两者优势,实现高效、可扩展的CMS解决方案,适应未来智能化、个性化的趋势。
|
1月前
|
存储 SQL 数据库
【python】python鲜花管理系统(界面GUI版本)(源码+数据库)【独一无二】
【python】python鲜花管理系统(界面GUI版本)(源码+数据库)【独一无二】
|
1月前
|
存储 人工智能 搜索推荐
【python】python用户管理系统[简易版](源码+报告)【独一无二】
【python】python用户管理系统[简易版](源码+报告)【独一无二】
|
1月前
|
人工智能 机器人 测试技术
【Python】Python仓储管理系统(源码)【独一无二】
【Python】Python仓储管理系统(源码)【独一无二】
|
1月前
|
Python
【Python】8. 学生管理系统(简易版)
【Python】8. 学生管理系统(简易版)
25 1

推荐镜像

更多