当前位置: 首页 >资讯 > >正文

多线程界面化、ONNXRUNTIME+YOLOv8推理演示 全球看点

来源:面包芯语 发布时间:2023-05-21 22:09:07


(资料图片仅供参考)

classYOLOv8InferPanel(QtWidgets.QWidget):def__init__(self,parent=None):super().__init__(parent)#文本标签self.rbtn0=QtWidgets.QRadioButton("对象检测")self.rbtn1=QtWidgets.QRadioButton("实例分割")self.rbtn3=QtWidgets.QRadioButton("姿态评估")self.rbtn0.setChecked(True)hbox_layout1=QtWidgets.QHBoxLayout()hbox_layout1.addWidget(self.rbtn0)hbox_layout1.addWidget(self.rbtn1)hbox_layout1.addWidget(self.rbtn3)panel3=QtWidgets.QGroupBox("推理类型")panel3.setLayout(hbox_layout1)#输入文本框self.image_file_edit=QtWidgets.QLineEdit()self.image_file_edit.setMinimumWidth(100)self.image_file_edit.setEnabled(False)fileBtn=QtWidgets.QPushButton("图像文件")self.weight_file_path=QtWidgets.QLineEdit()self.weight_file_path.setMinimumWidth(100)self.weight_file_path.setEnabled(False)modelBtn=QtWidgets.QPushButton("模型文件")self.label_file_path=QtWidgets.QLineEdit()self.label_file_path.setMinimumWidth(100)self.label_file_path.setEnabled(False)labelBtn=QtWidgets.QPushButton("标签文件")self.conf_spinbox=QtWidgets.QDoubleSpinBox()self.conf_spinbox.setRange(0,1)self.conf_spinbox.setSingleStep(0.01)self.conf_spinbox.setValue(0.25)grid_layout2=QtWidgets.QGridLayout()grid_layout2.addWidget(fileBtn,0,0)grid_layout2.addWidget(self.image_file_edit,0,1)grid_layout2.addWidget(modelBtn,0,2)grid_layout2.addWidget(self.weight_file_path,0,3)grid_layout2.addWidget(labelBtn,1,0)grid_layout2.addWidget(self.label_file_path,1,1)grid_layout2.addWidget(QtWidgets.QLabel("置信:"),1,2)grid_layout2.addWidget(self.conf_spinbox,1,3)panel2=QtWidgets.QGroupBox("参数设置")panel2.setLayout(grid_layout2)#输入文本框self.label=QtWidgets.QLabel()self.label.setMinimumSize(1280,720)pixmap=QtGui.QPixmap("images/wp.jpg")pix=pixmap.scaled(QtCore.QSize(1280,720),QtCore.Qt.KeepAspectRatio)self.label.setPixmap(pix)self.label.setAlignment(QtCore.Qt.AlignCenter)self.label.setStyleSheet("background-color:black;color:green")self.startBtn=QtWidgets.QPushButton("开始推理")self.stopBtn=QtWidgets.QPushButton("停止")self.startBtn.setStyleSheet("background-color:cyan;color:black")self.stopBtn.setStyleSheet("background-color:gray;color:white")self.stopBtn.setEnabled(False)hbox_layout=QtWidgets.QHBoxLayout()hbox_layout.addStretch(1)hbox_layout.addWidget(self.startBtn)hbox_layout.addWidget(self.stopBtn)panel1=QtWidgets.QWidget()panel1.setLayout(hbox_layout)#添加到布局管理器中vbox_layout=QtWidgets.QVBoxLayout()vbox_layout.addWidget(panel3)vbox_layout.addWidget(panel2)vbox_layout.addWidget(panel1)vbox_layout.addWidget(self.label)vbox_layout.addStretch(1)#面板容器self.setLayout(vbox_layout)#setuplistenermodelBtn.clicked.connect(self.on_weight_select)fileBtn.clicked.connect(self.on_update_image)labelBtn.clicked.connect(self.on_label_select)self.startBtn.clicked.connect(self.on_yolov8_infer)self.work_thread=None
classInferenceThread(QtCore.QThread):fire_stats_signal=QtCore.pyqtSignal(dict)def__init__(self,settings):super(InferenceThread,self).__init__()self.settings=settingsself.detector=Noneifself.settings.model_type==0:self.detector=YOLOv8ORTDetector(settings)ifself.settings.model_type==1:self.detector=YOLOv8ORTSegment(settings)ifself.settings.model_type==2:self.detector=YOLOv8ORTPose(settings)self.input_image=settings.input_imagedefrun(self):ifself.detectorisNone:returnifself.input_image.endswith(".mp4"):cap=cv.VideoCapture(self.input_image)whileTrue:ret,frame=cap.read()ifretisTrue:self.detector.infer_image(frame)self.fire_stats_signal.emit({"result":frame})else:breakelse:frame=cv.imread(self.input_image)self.detector.infer_image(frame)self.fire_stats_signal.emit({"result":frame})self.fire_stats_signal.emit({"done":"done"})return
#初始化APP实例importplatformapp=QtWidgets.QApplication(sys.argv)if"Windows"==platform.system():app.setStyle("Windows")#初始化桌面容器main_win=QtWidgets.QMainWindow()#设置APP窗口名称main_win.setWindowTitle("YOLOv8多线程推理应用演示-2号高手")#初始化内容面板content_panel=YOLOv8InferPanel()#设置窗口大小main_win.setMinimumSize(1340,960)main_win.setCentralWidget(content_panel)#请求显示main_win.show()#加载窗口并启动Appapp.exec()
上一篇:

环球动态:生涯第20年,终于该妥协了!从威少离开起,就注定了湖人的结局

下一篇:

最后一页

x
精彩推送