当前位置: 首页 > news >正文

【Yolov8】图形化检测视频-源码免费分享

如果你还不懂YOLOv8的安装、推理,自定义数据集训练与搭建的,可以看一下老师这篇文章和视频
https://blog.csdn.net/chajinglong/article/details/149105590?spm=1001.2014.3001.5501https://blog.csdn.net/chajinglong/article/details/149105590?spm=1001.2014.3001.5501

https://www.bilibili.com/video/BV1qtHeeMEnC/?spm_id_from=333.337.search-card.all.click&vd_source=27c8ea1c143ecfe9f586177e5e7027cfhttps%3A%2F%2Fwww.bilibili.com%2Fvideo%2FBV1qtHeeMEnC%2F%3Fspm_id_from%3D333.337.search-card.all.click&vd_source=27c8ea1c143ecfe9f586177e5e7027cfhttps://www.bilibili.com/video/BV1qtHeeMEnC/?spm_id_from=333.337.search-card.all.click&vd_source=27c8ea1c143ecfe9f586177e5e7027cfhttps%3A%2F%2Fwww.bilibili.com%2Fvideo%2FBV1qtHeeMEnC%2F%3Fspm_id_from%3D333.337.search-card.all.click&vd_source=27c8ea1c143ecfe9f586177e5e7027cf

很多同学问老师,这些课程能不能把文档写出来,分享到更多的人,那么今天它来了,整理成大纲给到同学们,希望能够帮助到你们,如果觉得写的可以,可以对照上面的视频和详细资料进行学习。

【YOLOv8零基础从入门到实战进阶系列教程】

https://www.bilibili.com/cheese/play/ep1342527?query_from=0&search_id=6883789517812043464&search_query=yolov8&csource=common_hpsearch_null_null&spm_id_from=333.337.search-card.all.clickhttps://www.bilibili.com/cheese/play/ep1342527?query_from=0&search_id=6883789517812043464&search_query=yolov8&csource=common_hpsearch_null_null&spm_id_from=333.337.search-card.all.click

​​

基于yolov8图形化目标检测视频(PyQt5 + ultralytics):

  1. 使用YOLO模型进行目标检测
  2. 处理图片和视频流
  3. 实现检测结果GUI可视化
import sys #用于退出程序 from PyQt5.QtCore import Qt,QTimer #这些是 PyQt5 库的模块,用于构建图形用户界面(GUI)应用程序 from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QVBoxLayout, QWidget, QPushButton, QHBoxLayout, \ QMessageBox, QFileDialog from PyQt5.QtGui import QImage, QPixmap import cv2 #图像处理 from ultralytics import YOLO #深度学习模型接口,用于加载 YOLO(You Only Look Once)模型进行对象检测 #负责处理模型加载和图像检测的逻辑。 class Worker: def __init__(self): self.model = None #加载模型 def load_model(self): model_path, _ = QFileDialog.getOpenFileName(None, "选择模型文件", "", "模型文件 (*.pt)") if model_path: self.model = YOLO(model_path) if self.model: return True else: return False #检测图片 def detect_image(self, image_path): image = cv2.imread(image_path) if image is not None: results = self.model.predict(image) return results else: return None #打开视频 def detect_video(self, video_path): # 打开视频文件 self.cap = cv2.VideoCapture(video_path) if not self.cap.isOpened(): return False return True #获取视频标注图像 def get_frame(self): if self.cap is not None and self.cap.isOpened(): ret, frame = self.cap.read() if ret: # 使用 YOLO 进行对象检测 results = self.model.predict(frame) annotated_frame = results[0].plot() # 用检测结果标注图像 return annotated_frame return None #释放 def release(self): if self.cap: self.cap.release() #应用程序的主窗口,负责创建界面,处理用户交互和显示检测结果 class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("YOLOv8-GUI(图形化界面)") """ 第一个:100,左上角屏幕左边缘水平距离(像素) 第二个:100,左上角屏幕上边缘垂直距离(像素) 第三个:100,设置窗口的宽度 第四个:100,设置窗口的高度 """ self.setGeometry(100, 100, 1200, 800) self.label = QLabel() self.label.setAlignment(Qt.AlignCenter) self.label.setFixedSize(640,480) layout = QVBoxLayout() layout.addWidget(self.label) central_widget = QWidget() central_widget.setLayout(layout) self.setCentralWidget(central_widget) self.worker = Worker() # 创建按钮布局 hbox_buttons = QHBoxLayout() layout.addLayout(hbox_buttons) # 添加模型选择按钮 self.load_model_button = QPushButton("模型选择") self.load_model_button.clicked.connect(self.load_model) hbox_buttons.addWidget(self.load_model_button) # 添加图片检测按钮 self.image_detect_button = QPushButton("图片检测") self.image_detect_button.clicked.connect(self.detect_image) self.image_detect_button.setEnabled(False) hbox_buttons.addWidget(self.image_detect_button) #添加视频检测按钮 self.video_detect_button = QPushButton("视频检测") self.video_detect_button.clicked.connect(self.detect_video) self.video_detect_button.setEnabled(False) hbox_buttons.addWidget(self.video_detect_button) # 添加退出按钮 self.exit_button = QPushButton("退出") self.exit_button.clicked.connect(self.exit_application) hbox_buttons.addWidget(self.exit_button) #定时器更新视频 self.timer = QTimer(self) self.timer.timeout.connect(self.update_frame) def detect_image(self): image_path, _ = QFileDialog.getOpenFileName(None, "选择图片文件", "", "图片文件 (*.jpg *.jpeg *.png)") if image_path: results = self.worker.detect_image(image_path) if results: annotated_image = results[0].plot() height, width, channel = annotated_image.shape bytesPerLine = 3 * width qimage = QImage(annotated_image.data, width, height, bytesPerLine, QImage.Format_BGR888) pixmap = QPixmap.fromImage(qimage) self.label.setPixmap(pixmap.scaled(self.label.size(), Qt.KeepAspectRatio)) else: QMessageBox.critical(self, "错误", "请选择图片文件") #选择视频文件 def detect_video(self): video_path, _ = QFileDialog.getOpenFileName(None, "选择视频文件", "", "视频文件 (*.mp4 *.avi *.mov)") if video_path: if self.worker.detect_video(video_path): # 开始定时器逐帧处理视频 self.timer.start(30) # 每30ms更新一次 (大约每秒更新33帧) else: QMessageBox.critical(self, "错误", "无法打开视频文件") else: QMessageBox.critical(self, "错误", "请选择视频文件") #更新视频 def update_frame(self): frame = self.worker.get_frame() if frame is not None: # 获取视频帧的宽高 height, width, channel = frame.shape bytesPerLine = 3 * width qimage = QImage(frame.data, width, height, bytesPerLine, QImage.Format_BGR888) # 创建 QPixmap 并按固定尺寸显示 pixmap = QPixmap.fromImage(qimage) # 按照 Qlabel 固定的尺寸显示,保持宽高比 self.label.setPixmap(pixmap.scaled(self.label.size(), Qt.KeepAspectRatio)) else: self.timer.stop() # 停止定时器,视频播放完毕 QMessageBox.information(self, "提示", "视频播放完毕") def load_model(self): if self.worker.load_model(): self.image_detect_button.setEnabled(True) self.video_detect_button.setEnabled(True) def exit_application(self): # 终止程序运行 sys.exit() if __name__ == '__main__': app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_())

如果这篇文章对你有所帮助,那就感谢同学的分享,转载,你们的分享是老师最大的动力

http://www.cnnetsun.cn/news/123021.html

相关文章:

  • MZmine 3实战指南:轻松掌握质谱数据分析三大核心技巧
  • ScienceDecrypting:免费CAJ转PDF终极指南,轻松突破文档限制
  • 如何高效使用ncmdump工具完成NCM文件批量转换
  • SetDPI:Windows多显示器DPI调整的终极解决方案
  • Kotaemon如何支持语音输入与输出转换?
  • 如何快速实现Vue音频播放功能:vue-audio-player终极解决方案
  • AutoDock Vina实战完整指南:从零掌握分子对接核心技巧
  • 终极指南:HexEdit十六进制编辑器的7大核心功能解析
  • 中文BERT-wwm模型多框架兼容实战:从问题排查到高效部署
  • New_lxmusic_source音源修复终极指南:彻底解决音乐播放难题
  • 终极指南:抖音批量下载工具的完整使用教程
  • Netgear路由器终极拯救指南:nmrpflash完整使用教程
  • BabelDOC智能文档翻译:让跨语言阅读不再是技术难题
  • wflow工作流设计器:让企业流程管理变得简单高效
  • 阴阳师自动化脚本百鬼夜行功能优化:3步提升碎片获取效率的完整指南
  • Kettle调度监控平台完整部署与配置指南
  • vmrc虚拟化管理工具:重新定义命令行虚拟机操作体验
  • 中国运营商IP地址库完整指南:免费获取精准网络数据
  • 群晖NAS搭建私有电子书阅读平台完全指南
  • Kotaemon智能代理的跨平台兼容性分析
  • EdgeRemover终极指南:Windows系统Edge浏览器一键管理方案
  • 快速提升Win11性能:5分钟完成终极系统优化指南
  • OpenHTMLtoPDF:Java开发者的HTML转PDF终极解决方案
  • 5分钟极速配置:Sunshine游戏串流性能提升实战手册
  • Kotaemon + 大模型Token售卖:一站式AI服务闭环
  • Windows美化终极教程:5分钟让资源管理器焕然一新
  • CQUThesis:重庆大学毕业论文排版的终极解决方案
  • OpenHTMLtoPDF终极指南:3小时从零掌握Java HTML转PDF
  • 企业如何快速落地智能客服?Kotaemon给出标准答案
  • Kotaemon开源了!专为复杂对话系统打造的智能代理引擎