**关键词**基于深度学习/YOLOV11的车辆类型检测系统YOLOv11、深度学习、目标检测、计算机视觉、车辆识别应用场景 智能交通监控、车辆分类统计、特种车辆救护车识别、道路安全分析开发技术 Python、PySide6、Ultralytics、OpenCV、Anaconda、PyTorch1111基于YOLOv11的车辆类型检测系统支持 PySide6 图形界面具备图片、视频、摄像头等多模态检测功能。以下是该项目的关键词表格和构建代码。 车辆类型检测系统关键词表关键词类别关键词核心算法YOLOv11、深度学习、目标检测、计算机视觉、车辆识别应用场景智能交通监控、车辆分类统计、特种车辆救护车识别、道路安全分析开发技术Python、PySide6、Ultralytics、OpenCV、Anaconda、PyTorch检测类别救护车 (Ambulance)、公交车 (Bus)、汽车 (Car)、卡车 (Truck)系统功能图片/视频/摄像头检测、批量处理、结果保存、中文类别显示、检测时间记录 系统构建详细代码本代码基于PySide6和Ultralytics YOLOv11构建。它实现了您图片中展示的图形用户界面系统包含图片检测、视频检测、摄像头实时检测、结果表格显示、置信度调节、保存检测结果等功能。环境准备在运行代码前请确保已安装必要的库pipinstallPySide6 opencv-python ultralytics torch torchvision完整代码将以下代码保存为main.py。请确保你有一个训练好的模型权重文件例如best.pt或者修改代码中的MODEL_PATH指向你下载的官方模型如yolov11n.pt。importsysimportcv2importtorchimporttimeimportosimportjsonfromPySide6.QtWidgetsimport(QApplication,QMainWindow,QWidget,QVBoxLayout,QHBoxLayout,QLabel,QPushButton,QTableWidget,QTableWidgetItem,QFileDialog,QMessageBox,QComboBox,QDoubleSpinBox)fromPySide6.QtGuiimportQImage,QPixmap,QFontfromPySide6.QtCoreimportQt,QTimer,QThread,SignalfromultralyticsimportYOLO# 配置部分 MODEL_PATHbest.pt# 替换为你的模型路径CLASS_MAPPING{Ambulance:救护车,Bus:公交车,Car:汽车,Truck:卡车}# 检测线程 classDetectThread(QThread):# 信号检测结果 (图像, 结果列表, 用时)result_readySignal(QImage,list,float)finishedSignal()def__init__(self,source,model,conf_threshold0.25):super().__init__()self.sourcesource# 图片路径/视频路径/摄像头索引self.modelmodel self.conf_thresholdconf_threshold self.runningTruedefrun(self):ifisinstance(self.source,str)andself.source.endswith((.mp4,.avi,.mov)):# 视频检测capcv2.VideoCapture(self.source)whileself.runningandcap.isOpened():ret,framecap.read()ifnotret:breakstart_timetime.time()resultsself.model(frame,confself.conf_threshold)detect_timetime.time()-start_time# 处理结果result_img,result_listself.process_results(frame,results[0])self.result_ready.emit(result_img,result_list,detect_time)time.sleep(0.03)# 控制帧率cap.release()elifisinstance(self.source,int):# 摄像头检测capcv2.VideoCapture(self.source)whileself.running:ret,framecap.read()ifnotret:breakstart_timetime.time()resultsself.model(frame,confself.conf_threshold)detect_timetime.time()-start_time# 处理结果result_img,result_listself.process_results(frame,results[0])self.result_ready.emit(result_img,result_list,detect_time)time.sleep(0.03)cap.release()else:# 图片检测framecv2.imread(self.source)start_timetime.time()resultsself.model(frame,confself.conf_threshold)detect_timetime.time()-start_time# 处理结果result_img,result_listself.process_results(frame,results[0])self.result_ready.emit(result_img,result_list,detect_time)self.finished.emit()defprocess_results(self,frame,result):# 绘制检测框result_imgframe.copy()result_list[]forboxinresult.boxes:x1,y1,x2,y2map(int,box.xyxy[0])confbox.conf[0]clsint(box.cls[0])labelresult.names[cls]chinese_labelCLASS_MAPPING.get(label,label)# 绘制矩形框cv2.rectangle(result_img,(x1,y1),(x2,y2),(0,255,0),2)# 绘制标签cv2.putText(result_img,f{chinese_label}{conf:.2f},(x1,y1-10),cv2.FONT_HERSHEY_SIMPLEX,0.5,(0,255,0),2)result_list.append({label:chinese_label,conf:conf,x1:x1,y1:y1,x2:x2,y2:y2})# 转换为QImageresult_imgcv2.cvtColor(result_img,cv2.COLOR_BGR2RGB)h,w,chresult_img.shape bytes_per_linech*w q_imgQImage(result_img.data,w,h,bytes_per_line,QImage.Format_RGB888)returnq_img,result_listdefstop(self):self.runningFalseself.wait()# 主窗口 classMainWindow(QMainWindow):def__init__(self):super().__init__()self.setWindowTitle(基于YOLOv11的车辆类型检测系统)self.setGeometry(100,100,1200,800)# 加载模型self.modelYOLO(MODEL_PATH)# UI组件self.image_labelQLabel(检测区域)self.image_label.setFixedSize(800,600)self.image_label.setStyleSheet(background-color: #f0f0f0; border: 1px solid #ccc;)self.result_tableQTableWidget()self.result_table.setColumnCount(6)self.result_table.setHorizontalHeaderLabels([序号,文件路径,检测结果,YOLO置信度,坐标位置,检测时间(s)])self.result_table.horizontalHeader().setStretchLastSection(True)self.conf_spinboxQDoubleSpinBox()self.conf_spinbox.setRange(0.01,1.0)self.conf_spinbox.setValue(0.25)self.conf_spinbox.setSingleStep(0.05)self.detect_buttonQPushButton(图片检测)self.video_buttonQPushButton(视频检测)self.camera_buttonQPushButton(摄像头检测)self.save_buttonQPushButton(保存结果)self.exit_buttonQPushButton(退出)# 布局top_layoutQHBoxLayout()top_layout.addWidget(self.image_label)top_layout.addWidget(self.result_table)bottom_layoutQHBoxLayout()bottom_layout.addWidget(QLabel(YOLO置信度:))bottom_layout.addWidget(self.conf_spinbox)bottom_layout.addWidget(self.detect_button)bottom_layout.addWidget(self.video_button)bottom_layout.addWidget(self.camera_button)bottom_layout.addWidget(self.save_button)bottom_layout.addWidget(self.exit_button)main_layoutQVBoxLayout()main_layout.addLayout(top_layout)main_layout.addLayout(bottom_layout)containerQWidget()container.setLayout(main_layout)self.setCentralWidget(container)# 信号连接self.detect_button.clicked.connect(self.detect_image)self.video_button.clicked.connect(self.detect_video)self.camera_button.clicked.connect(self.detect_camera)self.save_button.clicked.connect(self.save_results)self.exit_button.clicked.connect(self.close)# 检测线程self.detect_threadNonedefdetect_image(self):file_path,_QFileDialog.getOpenFileName(self,选择图片,,Image Files (*.png *.jpg *.bmp))iffile_path:self.start_detection(file_path)defdetect_video(self):file_path,_QFileDialog.getOpenFileName(self,选择视频,,Video Files (*.mp4 *.avi *.mov))iffile_path:self.start_detection(file_path)defdetect_camera(self):self.start_detection(0)# 0表示默认摄像头defstart_detection(self,source):ifself.detect_thread:self.detect_thread.stop()self.detect_threadDetectThread(source,self.model,self.conf_spinbox.value())self.detect_thread.result_ready.connect(self.update_results)self.detect_thread.start()defupdate_results(self,q_img,result_list,detect_time):# 显示图像pixmapQPixmap.fromImage(q_img)self.image_label.setPixmap(pixmap.scaled(self.image_label.size(),Qt.KeepAspectRatio))# 更新表格self.result_table.setRowCount(len(result_list))fori,resultinenumerate(result_list):self.result_table.setItem(i,0,QTableWidgetItem(str(i1)))self.result_table.setItem(i,1,QTableWidgetItem(检测中...))self.result_table.setItem(i,2,QTableWidgetItem(result[label]))self.result_table.setItem(i,3,QTableWidgetItem(f{result[conf]:.2f}))self.result_table.setItem(i,4,QTableWidgetItem(f({result[x1]},{result[y1]},{result[x2]},{result[y2]})))self.result_table.setItem(i,5,QTableWidgetItem(f{detect_time:.2f}))defsave_results(self):# 保存检测结果到文件file_path,_QFileDialog.getSaveFileName(self,保存结果,,Text Files (*.txt))iffile_path:withopen(file_path,w,encodingutf-8)asf:forrowinrange(self.result_table.rowCount()):row_data[]forcolinrange(self.result_table.columnCount()):itemself.result_table.item(row,col)row_data.append(item.text()ifitemelse)f.write(\t.join(row_data)\n)QMessageBox.information(self,保存成功,检测结果已保存)defcloseEvent(self,event):ifself.detect_thread:self.detect_thread.stop()event.accept()# 启动程序 if__name____main__:appQApplication(sys.argv)windowMainWindow()window.show()sys.exit(app.exec()) 如何运行准备模型文件将你训练好的best.pt文件放在项目根目录或者修改代码中的MODEL_PATH指向你的模型路径。运行程序python main.py使用功能点击“图片检测”选择图片进行检测。点击“视频检测”选择视频文件进行检测。点击“摄像头检测”开启实时摄像头检测。检测结果会显示在表格中并可选择保存。该系统完全复刻了你提供的界面功能支持中文类别显示、检测时间记录、结果保存等特性。