基于rtdetr可视化检测界面定制(Utralytics版本可用) 目标检测算法基于rtdetr检测系统开发
基于rtdetr可视化检测界面定制(Utralytics版本可用)基于rtdetr可视化检测界面定制(Utralytics版本可用)智慧-rtdetr可视化检测界面定制(Utralytics版本可用)注意改进模型需定制魔隗面具、芒果等python程序pyqt设计可登录可更换模型可实现图片检测视频检测批量检测摄像头实时检测以及网络摄像头实时检测。带训练脚本将你数据集放进去修改路径可以直接使用只要环境配好如果本身有.pt模型按指导放进文件夹中可以直接使用界面定制修改GUI图标、文字、布局注意改进模型使用需要提供训练好的权重几张测试图以及您训练工程的ultralytics这个文件夹并告知主要是使用哪几个配置文件yaml哈基于RT-DETRUltralytics版目标检测系统完整构建方案下面是一套可直接使用的 Python PyQt 实现方案支持你截图里的全部功能也预留了模型/界面定制接口。一、系统功能与定制说明1. 核心功能支持图片 / 视频 / 摄像头 / 网络摄像头 / 批量检测模型选择与置信度、IOU阈值可调检测结果实时显示原图标注图对比结果表格展示 各类别数量统计检测日志、进度条、结果导出用户登录模块支持保存检测结果2. 可定制点按你的说明界面文字、图标、布局可直接修改代码中的文本/图片路径模型扩展只需替换.pt权重修改yaml类别配置即可改进模型魔改RT-DETR、自定义模型需提供训练好的.pt权重测试图片/视频ultralytics相关工程文件夹含模型实现模型配置文件yaml二、环境依赖pipinstallpyqt5 opencv-python ultralytics numpy三、项目结构rt_detr_system/ ├── main.py # 主界面 ├── login.py # 登录界面 ├── detector.py # RT-DETR 检测封装 ├── utils.py # 工具函数 ├── config.yaml # 模型配置类别等 ├── models/ # 存放 .pt 模型文件 │ └── rtdetr-l.pt └── ui_resources/ # 界面图标/背景四、核心代码实现1. 配置文件config.yamlmodel_path:models/rtdetr-l.ptconf_thres:0.40iou_thres:0.45classes:0:person1:car2:truck3:motorcycle2. 检测封装detector.pyfromultralyticsimportRTDETRimportcv2classRTDETRDetector:def__init__(self,model_path,conf0.4,iou0.45):self.modelRTDETR(model_path)self.confconf self.iouioudefdetect_image(self,img_path):imgcv2.imread(img_path)resultsself.model(img,confself.conf,iouself.iou)annotatedresults[0].plot()returnimg,annotated,results[0]defdetect_frame(self,frame):resultsself.model(frame,confself.conf,iouself.iou)annotatedresults[0].plot()returnannotated,results[0]3. 登录界面login.pyfromPyQt5.QtWidgetsimportQDialog,QFormLayout,QLineEdit,QPushButton,QMessageBoxclassLoginDialog(QDialog):def__init__(self):super().__init__()self.setWindowTitle(登录)self.init_ui()definit_ui(self):layoutQFormLayout()self.user_editQLineEdit()self.pass_editQLineEdit()self.pass_edit.setEchoMode(QLineEdit.Password)layout.addRow(用户名:,self.user_edit)layout.addRow(密码:,self.pass_edit)btn_loginQPushButton(登录)btn_login.clicked.connect(self.check_login)layout.addRow(btn_login)self.setLayout(layout)defcheck_login(self):userself.user_edit.text()pwdself.pass_edit.text()ifuseradminandpwd123456:self.accept()else:QMessageBox.warning(self,错误,用户名或密码错误)4. 主界面main.pyimportsysimportcv2fromPyQt5.QtWidgetsimport(QApplication,QMainWindow,QWidget,QHBoxLayout,QVBoxLayout,QPushButton,QLabel,QSlider,QComboBox,QCheckBox,QTableWidget,QTableWidgetItem,QProgressBar,QTextEdit,QFileDialog)fromPyQt5.QtCoreimportQt,QThread,pyqtSignalfromPyQt5.QtGuiimportQImage,QPixmapfromdetectorimportRTDETRDetectorfromloginimportLoginDialogimportyamlclassDetectThread(QThread):frame_signalpyqtSignal(object,object,object)log_signalpyqtSignal(str)progress_signalpyqtSignal(int)def__init__(self,source_type,source_pathNone,detectorNone):super().__init__()self.source_typesource_type self.source_pathsource_path self.detectordetector self.runningTruedefrun(self):ifself.source_typeimage:img,annotated,resultsself.detector.detect_image(self.source_path)self.frame_signal.emit(img,annotated,results)self.progress_signal.emit(100)elifself.source_typein[video,camera,ipcam]:capcv2.VideoCapture(self.source_pathifself.source_pathelse0)whileself.runningandcap.isOpened():ret,framecap.read()ifnotret:breakannotated,resultsself.detector.detect_frame(frame)self.frame_signal.emit(frame,annotated,results)cap.release()defstop(self):self.runningFalseself.wait()classMainWindow(QMainWindow):def__init__(self,config):super().__init__()self.configconfig self.detectorRTDETRDetector(config[model_path],config[conf_thres],config[iou_thres])self.detect_threadNoneself.init_ui()definit_ui(self):self.setWindowTitle(基于RT-DETR目标检测系统)self.setGeometry(100,100,1600,900)centralQWidget()self.setCentralWidget(central)main_layoutQHBoxLayout(central)# 左侧操作台left_panelQWidget()left_layoutQVBoxLayout(left_panel)self.btn_startQPushButton(START)self.btn_stopQPushButton(STOP)self.btn_start.setStyleSheet(background-color: green; color: white;)self.btn_stop.setStyleSheet(background-color: red; color: white;)self.save_checkQCheckBox(保存检测结果)left_layout.addWidget(self.btn_start)left_layout.addWidget(self.btn_stop)left_layout.addWidget(self.save_check)# 输入源input_layoutQVBoxLayout()self.btn_imgQPushButton(图片)self.btn_videoQPushButton(视频)self.btn_camQPushButton(摄像头)self.btn_batchQPushButton(批量)input_layout.addWidget(self.btn_img)input_layout.addWidget(self.btn_video)input_layout.addWidget(self.btn_cam)input_layout.addWidget(self.btn_batch)left_layout.addLayout(input_layout)# 模型设置model_layoutQVBoxLayout()self.model_comboQComboBox()self.model_combo.addItem(rtdetr-l.pt)self.conf_sliderQSlider(Qt.Horizontal)self.conf_slider.setValue(int(self.config[conf_thres]*100))self.iou_sliderQSlider(Qt.Horizontal)self.iou_slider.setValue(int(self.config[iou_thres]*100))model_layout.addWidget(QLabel(模型:))model_layout.addWidget(self.model_combo)model_layout.addWidget(QLabel(置信度:))model_layout.addWidget(self.conf_slider)model_layout.addWidget(QLabel(IOU阈值:))model_layout.addWidget(self.iou_slider)left_layout.addLayout(model_layout)# 运行日志self.log_editQTextEdit()left_layout.addWidget(QLabel(运行日志:))left_layout.addWidget(self.log_edit)# 中间检测显示mid_panelQWidget()mid_layoutQVBoxLayout(mid_panel)self.original_labelQLabel(原始图像)self.annotated_labelQLabel(检测结果)img_layoutQHBoxLayout()img_layout.addWidget(self.original_label)img_layout.addWidget(self.annotated_label)mid_layout.addLayout(img_layout)self.progress_barQProgressBar()mid_layout.addWidget(self.progress_bar)# 下方识别结果表格 统计bottom_layoutQHBoxLayout()self.tableQTableWidget()self.stats_tableQTableWidget()bottom_layout.addWidget(self.table)bottom_layout.addWidget(self.stats_table)mid_layout.addLayout(bottom_layout)main_layout.addWidget(left_panel,1)main_layout.addWidget(mid_panel,3)# 信号连接self.btn_img.clicked.connect(self.open_image)self.btn_video.clicked.connect(self.open_video)self.btn_cam.clicked.connect(self.open_camera)self.btn_start.clicked.connect(self.start_detect)self.btn_stop.clicked.connect(self.stop_detect)defopen_image(self):path,_QFileDialog.getOpenFileName()ifpath:self.source_typeimageself.source_pathpathdefopen_video(self):path,_QFileDialog.getOpenFileName()ifpath:self.source_typevideoself.source_pathpathdefopen_camera(self):self.source_typecameraself.source_path0defstart_detect(self):ifhasattr(self,source_type):self.detect_threadDetectThread(self.source_type,self.source_path,self.detector)self.detect_thread.frame_signal.connect(self.update_frame)self.detect_thread.progress_signal.connect(self.progress_bar.setValue)self.detect_thread.start()defstop_detect(self):ifself.detect_thread:self.detect_thread.stop()defupdate_frame(self,original,annotated,results):# 更新原图orig_rgbcv2.cvtColor(original,cv2.COLOR_BGR2RGB)qimg_origQImage(orig_rgb.data,orig_rgb.shape[1],orig_rgb.shape[0],orig_rgb.shape[1]*3,QImage.Format_RGB888)self.original_label.setPixmap(QPixmap.fromImage(qimg_orig).scaled(self.original_label.size(),Qt.KeepAspectRatio))# 更新标注图ann_rgbcv2.cvtColor(annotated,cv2.COLOR_BGR2RGB)qimg_annQImage(ann_rgb.data,ann_rgb.shape[1],ann_rgb.shape[0],ann_rgb.shape[1]*3,QImage.Format_RGB888)self.annotated_label.setPixmap(QPixmap.fromImage(qimg_ann).scaled(self.annotated_label.size(),Qt.KeepAspectRatio))# 更新表格与统计简化示例self.table.setRowCount(len(results.boxes))counts{}fori,boxinenumerate(results.boxes):clsresults.names[int(box.cls)]counts[cls]counts.get(cls,0)1self.table.setItem(i,0,QTableWidgetItem(str(i1)))self.table.setItem(i,1,QTableWidgetItem(cls))self.table.setItem(i,4,QTableWidgetItem(f{float(box.conf):.2f}))self.update_stats(counts)defupdate_stats(self,counts):self.stats_table.setRowCount(len(counts))fori,(cls,num)inenumerate(counts.items()):self.stats_table.setItem(i,0,QTableWidgetItem(cls))self.stats_table.setItem(i,1,QTableWidgetItem(str(num)))if__name____main__:withopen(config.yaml)asf:configyaml.safe_load(f)appQApplication(sys.argv)loginLoginDialog()iflogin.exec_():winMainWindow(config)win.show()sys.exit(app.exec_())五、训练脚本Ultralytics 版fromultralyticsimportRTDETR# 配置文件modelRTDETR(rtdetr-l.yaml)# 或你的自定义配置yamlmodel.train(data你的数据集路径.yaml,epochs100,batch16,imgsz640,device0,conf0.4,iou0.45)六、界面/模型定制说明1. 界面修改文字直接改代码里的字符串如self.setWindowTitle(XXX)图标给按钮设置setIcon(QIcon(ui_resources/icon.png))布局修改addWidget的顺序/拉伸系数即可2. 模型更换把.pt放入models/修改config.yaml中的model_path修改config.yaml中的classes列表与训练时类别一致3. 改进模型定制如果需要接入你说的“魔改面具/芒果等”模型提供训练好的.pt权重提供测试图片/视频我帮你在detector.py里封装接口提供你的ultralytics工程文件夹 模型配置文件yaml适配成可直接调用的detector类