自学内容网 自学内容网

pyQt5实现目标检测可视化001

1.实验目的

由于最近开题答辩,需要进行可视化展示,于是学习了qt5进行可视化界面展示,这个有点像web前端,也有点像vue,所以还是蛮好玩的,想深入学习的朋友建议多加看看B站等专门系统教学课程,少走弯路,祝学习进步,天天开心~

2.实验环境搭建

  • 深度学习环境搭建anaconda+pycharm+NVIDA显卡驱动+cuda+cudnn+ pytorch(一定要版本对应,不然bug一堆);
  • pyQt5安装移机三大工具配置,这个可以百度下,很简单;

3.开始编写ui

以一个程序为例

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QLabel" name="label">
    <property name="geometry">
     <rect>
      <x>190</x>
      <y>45</y>
      <width>481</width>
      <height>61</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <family>黑体</family>
      <pointsize>26</pointsize>
     </font>
    </property>
    <property name="text">
     <string>智能动态视觉柜异物检测系统</string>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>800</width>
     <height>23</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>

PS:记得把你的图片和你的qrc,以及*rc.py文件放一起
在这里插入图片描述

4.转为python程序

在这里插入图片描述
按照上方操作做即可,不需要自己专门去写python代码的,那些都是ui工程师做的,我们只需要在qtdesigner中布局好就ok.

5.运行窗口

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'MainWindow2.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# 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
import carbinet_rc
import exit_rc
import img1_rc
import jump_rc


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(857, 745)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setEnabled(True)
        self.centralwidget.setObjectName("centralwidget")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(40, 10, 551, 51))
        font = QtGui.QFont()
        font.setFamily("Agency FB")
        font.setPointSize(36)
        self.label.setFont(font)
        self.label.setStyleSheet("color : rgb(255, 170, 255)\n"
"font: 17pt \"黑体\";")
        self.label.setObjectName("label")
        self.horizontalSlider = QtWidgets.QSlider(self.centralwidget)
        self.horizontalSlider.setGeometry(QtCore.QRect(70, 240, 160, 22))
        self.horizontalSlider.setOrientation(QtCore.Qt.Horizontal)
        self.horizontalSlider.setObjectName("horizontalSlider")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(10, 240, 54, 12))
        self.label_2.setObjectName("label_2")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(280, 250, 141, 23))
        self.pushButton.setObjectName("pushButton")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(320, 80, 61, 20))
        self.label_3.setObjectName("label_3")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(600, 80, 54, 12))
        self.label_4.setObjectName("label_4")
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(0, 160, 91, 31))
        self.label_5.setObjectName("label_5")
        self.toolButton_2 = QtWidgets.QToolButton(self.centralwidget)
        self.toolButton_2.setGeometry(QtCore.QRect(120, 170, 111, 18))
        self.toolButton_2.setObjectName("toolButton_2")
        self.label_6 = QtWidgets.QLabel(self.centralwidget)
        self.label_6.setGeometry(QtCore.QRect(240, 120, 211, 121))
        self.label_6.setStyleSheet("background-color: rgb(85, 255, 255);")
        self.label_6.setText("")
        self.label_6.setObjectName("label_6")
        self.label_7 = QtWidgets.QLabel(self.centralwidget)
        self.label_7.setGeometry(QtCore.QRect(530, 120, 211, 121))
        self.label_7.setStyleSheet("background-color: rgb(85, 255, 255);")
        self.label_7.setText("")
        self.label_7.setObjectName("label_7")
        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_2.setGeometry(QtCore.QRect(310, 290, 75, 23))
        self.pushButton_2.setObjectName("pushButton_2")
        self.label_8 = QtWidgets.QLabel(self.centralwidget)
        self.label_8.setGeometry(QtCore.QRect(0, 300, 71, 16))
        self.label_8.setObjectName("label_8")
        self.horizontalSlider_2 = QtWidgets.QSlider(self.centralwidget)
        self.horizontalSlider_2.setGeometry(QtCore.QRect(70, 300, 160, 22))
        self.horizontalSlider_2.setOrientation(QtCore.Qt.Horizontal)
        self.horizontalSlider_2.setObjectName("horizontalSlider_2")
        self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_3.setGeometry(QtCore.QRect(760, 90, 75, 23))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/exit/exit.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.pushButton_3.setIcon(icon)
        self.pushButton_3.setObjectName("pushButton_3")
        self.label_9 = QtWidgets.QLabel(self.centralwidget)
        self.label_9.setGeometry(QtCore.QRect(0, -40, 871, 711))
        self.label_9.setText("")
        self.label_9.setPixmap(QtGui.QPixmap(":/img1/img1.jpg"))
        self.label_9.setObjectName("label_9")
        self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_4.setGeometry(QtCore.QRect(100, 390, 121, 23))
        self.pushButton_4.setStyleSheet("icon:url(:/jump/jump.png)")
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(":/jump/jump.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.pushButton_4.setIcon(icon1)
        self.pushButton_4.setObjectName("pushButton_4")
        self.label_10 = QtWidgets.QLabel(self.centralwidget)
        self.label_10.setGeometry(QtCore.QRect(20, 390, 61, 20))
        self.label_10.setObjectName("label_10")
        self.label_9.raise_()
        self.label.raise_()
        self.horizontalSlider.raise_()
        self.label_2.raise_()
        self.pushButton.raise_()
        self.label_3.raise_()
        self.label_4.raise_()
        self.label_5.raise_()
        self.toolButton_2.raise_()
        self.label_6.raise_()
        self.label_7.raise_()
        self.pushButton_2.raise_()
        self.label_8.raise_()
        self.horizontalSlider_2.raise_()
        self.pushButton_3.raise_()
        self.pushButton_4.raise_()
        self.label_10.raise_()
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 857, 23))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)

        self.retranslateUi(MainWindow)
        self.pushButton_3.clicked.connect(MainWindow.close) # type: ignore
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label.setText(_translate("MainWindow", "智能视觉柜动态识别系统"))
        self.label_2.setText(_translate("MainWindow", "IOU:"))
        self.pushButton.setText(_translate("MainWindow", "上传图片/视频"))
        self.label_3.setText(_translate("MainWindow", "图片展示区"))
        self.label_4.setText(_translate("MainWindow", "识别结果"))
        self.label_5.setText(_translate("MainWindow", "请选择权重文件:"))
        self.toolButton_2.setText(_translate("MainWindow", "请选择权重文件"))
        self.pushButton_2.setText(_translate("MainWindow", "拍照"))
        self.label_8.setText(_translate("MainWindow", "Confidence:"))
        self.pushButton_3.setText(_translate("MainWindow", "退出系统"))
        self.pushButton_4.setText(_translate("MainWindow", "1.视频检测页面"))
        self.label_10.setText(_translate("MainWindow", "其他页面:"))

if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

在这里插入图片描述


原文地址:https://blog.csdn.net/qq_37269626/article/details/144583883

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!