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

news/2024/10/22 13:59:59/

 程序示例精选

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

如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!

前言

这篇博客针对<<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 QtWidgetsfrom PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

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'):breakself.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 cv2import numpy as npcount = 0recognizer = cv2.face.LBPHFaceRecognizer_create()recognizer.read('face_trainer/trainer.yml')cascadePath = "haarcascade_frontalface_default.xml"faceCascade = cv2.CascadeClassifier(cascadePath)font = cv2.FONT_HERSHEY_SIMPLEXprint("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.shapebytesPerLine = bytesPerComponent * widthself.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.shapebytesPerLine = bytesPerComponent * widthself.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()  

3. 运行结果

 

三、在线协助:

如需安装运行环境或远程调试,见文章底部个人 QQ 名片,由专业技术人员远程协助!
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++,网页领域博主


http://www.ppmy.cn/news/49126.html

相关文章

“行泊舱”+出海全面发力,这家ADAS厂商跑出规模化“新速度”

进入2023年&#xff0c;智能汽车市场已经由纯技术驱动迈入了市场驱动的新周期&#xff0c;接下来的市场竞争比拼的重点将是真正的规模化普及。 《高工智能汽车研究院》认为&#xff0c;中国乘用车市场已经来到了L2普及、L2冲刺发力以及L3/L4小规模落地的并行发展周期。对于智能…

grep -nr 命令查询字符串方式

grep -nr “搜索内容” 文件路径 其中&#xff1a; -n&#xff1a;显示行号-r&#xff1a;递归查找子目录中的文件“搜索内容”&#xff1a;要搜索的内容文件路径&#xff1a;要搜索的文件路径&#xff0c;可以是单个文件或目录路径&#xff08;将会递归搜索该目录下的所有文…

c++ 静态绑定和动态绑定

C 中有两种不同的函数调用方式&#xff1a;静态绑定和动态绑定。 静态绑定 静态绑定是指在编译时确定调用哪个函数。也就是说&#xff0c;编译器会根据函数调用的名称和参数类型来确定要调用的函数。这种方式也被称为静态多态或编译时多态。 静态绑定适用于以下情况&#xff…

如何恢复回收站中被删除的文件?高效的恢复技巧

一般情况下&#xff0c;我们从电脑上普通删除的文件&#xff0c;会经过回收站&#xff08;除非文件过大&#xff09;&#xff0c;想要在回收站找回删除的东西&#xff0c;是很简单的&#xff0c;我们只需要打开回收站&#xff0c;找到删除的文件&#xff0c;右键点击并选择还原…

three.js(JS 三维模型库)介绍和入门

介绍&#xff1a; three.js是一个基于WebGL的JavaScript 3D库。它封装了WebGL API&#xff0c;为开发者提供了简单易用的API&#xff0c;以便在Web浏览器中展示3D图形。three.js提供了几个组件、方法和工具&#xff0c;用于创建和处理3D图形&#xff0c;使得开发者可以在Web浏…

Python 环境搭建

Unix & Linux 平台安装 Python: 以下为在 Unix & Linux 平台上安装 Python 的简单步骤&#xff1a; 打开 WEB 浏览器访问https://www.python.org/downloads/source/选择适用 于Unix/Linux 的源码压缩包。下载及解压压缩包。如果你需要自定义一些选项修改Modules/Setu…

【软件测试二】开发模型和测试模型,BUG概念篇

目录 1.软件的生命周期 2.瀑布模型 3.螺旋模型 4.增量&#xff0c;迭代 5.敏捷---scrum 1. 敏捷宣言 2.角色 6. 软件测试v模型 7.软件测试w模型 8.软件测试的生命周期 9.如何描述一个BUG 10.如何定义BUG的级别 11.BUG的生命周期 12.产生争执怎么办 1.软件的生命周期…

【Java】Java8接口中方法区别和使用

Java接口说明 jdk1.8之前接口只能是抽象方法。实现接口必须重写所有方法&#xff0c;比较麻烦。在java8中&#xff0c;支持default和static方法&#xff0c;这样&#xff0c;实现接口时&#xff0c;可以选择是否对default修饰的方法重写。 抽象方法 接口当中的抽象方法&#x…