前期准备工作请看:
毕业设计:学生坐姿识别系统(1)——前期准备_一个爱python的小袁子的博客-CSDN博客
前期研究的方法以及思路请看:
毕业设计:学生坐姿识别系统(2)——中期:前期研究的方法以及思路_一个爱python的小袁子的博客-CSDN博客
中期基本功能的介绍以及少部分代码的注释请看:
毕业设计:学生坐姿识别系统(3)——中期:基本功能介绍以及少部分代码的注释_一个爱python的小袁子的博客-CSDN博客
上一篇文章最后生成了一个SVM模型:svm_model.pkl,这是整个项目的核心,之后增加图片数据进行训练时,需要重新训练验证,最后生成模型。
本篇内容安排如下:介绍本设计的系统设计、设计代码程序以及结果展示。
1.系统设计
所设计的系统设有登录界面和主界面。其中主界面所拥有的功能有选择图片文件、开始识别、显示识别结果、显示识别时间、显示所打开的图片文件、显示处理后的图片、退出登录以及最小化和退出。
说白了就是设计用户界面,用户界面的设计方法有很多,比如:Python-Tkinter 图形化界面设计、Python-wxPython 、Python-Pyqt等。
Python 小白从零开始 PyQt5 项目实战(8)汇总篇(完整例程) - 知乎
以上三种方法都有相应的参考资料,其中,我选择了使用了Python-PyQt进行用户界面设计。
注:使用Python-PyQt时需要先配置环境。
(1)下载安装pyqt5和pyqt5-tools两个模块;
(2)设置Qt工具,主要包括Qt Designer、PyUIC、PyRcc这三个工具。
PyQt5的配置过程资料很多,参考地址:pycharm+pyqt5快速入门(环境配置、UI界面设计、事件触发)_拔剑cPY的博客-CSDN博客
2.界面的设计步骤
1.先使用图形界面开发工具Qt Designer进行UI界面的编写,拖拽放置控件,并随时查看控件效果;
2.布控好UI界面的控件后,使用PyUIC工具将图形界面开发工具生成的文件转换成py文件,进行逻辑编程与修改。
(1)登录界面
对于登录界面的设计,我是参考网上的一些方法,最后由于时间关系,没有使用数据库,所以只能完成简单的登录过程,没有注册功能。
参考地址:Python/PyQt5/Qtdesigner设计精美登录界面-PART1_哔哩哔哩_bilibili
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'denglu_ui.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_login_MainWindow(object):
def setupUi(self, login_MainWindow):
login_MainWindow.setObjectName("login_MainWindow")
login_MainWindow.resize(749, 660)
self.centralwidget = QtWidgets.QWidget(login_MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(170, 30, 400, 500))
self.label.setStyleSheet("border-image: url(./ui_image/denglubackground.jpg);\n"
"border-radius:30px;")
self.label.setText("")
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(170, 30, 400, 500))
self.label_2.setStyleSheet("background-color: rgba(0, 0, 0, 150);\n"
"border-radius:30px;")
self.label_2.setText("")
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(300, 120, 161, 51))
font = QtGui.QFont()
font.setFamily("幼圆")
font.setPointSize(22)
font.setKerning(True)
self.label_3.setFont(font)
self.label_3.setStyleSheet("color: rgb(255, 255, 255);")
self.label_3.setObjectName("label_3")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(260, 220, 221, 51))
font = QtGui.QFont()
font.setPointSize(12)
self.lineEdit.setFont(font)
self.lineEdit.setStyleSheet("background-color: rgba(0, 0, 0, 0);\n"
"border: 1px solid rgba(0, 0, 0, 0);\n"
"border-bottom-color: rgba(255, 255, 255, 200);\n"
"color: rgb(255, 255, 255);")
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(260, 310, 221, 51))
font = QtGui.QFont()
font.setPointSize(12)
self.lineEdit_2.setFont(font)
self.lineEdit_2.setStyleSheet("background-color: rgba(0, 0, 0, 0);\n"
"border: 1px solid rgba(0, 0, 0, 0);\n"
"border-bottom-color: rgba(255, 255, 255, 200);\n"
"color: rgb(255, 255, 255);")
self.lineEdit_2.setText("")
self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)
self.lineEdit_2.setObjectName("lineEdit_2")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore