news 2026/4/16 13:30:25

基于深度学习YOLOv10的水藻检测系统(YOLOv10+YOLO数据集+UI界面+Python项目源码+模型)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
基于深度学习YOLOv10的水藻检测系统(YOLOv10+YOLO数据集+UI界面+Python项目源码+模型)

一、项目介绍

项目摘要

项目名称:YOLOv10水藻检测系统
项目目标:基于YOLOv10深度学习算法,开发一套高效、精准的水藻检测系统,用于实时监测水体中的藻类分布情况,支持水质评估、生态研究和环境治理。


项目背景

水藻是水体生态系统中重要的组成部分,但过量繁殖(如蓝藻水华)会导致水质恶化,影响水生生物生存,甚至威胁人类健康。传统的水藻监测方法主要依赖人工采样和实验室分析,存在以下问题:

  1. 效率低:人工采样耗时,难以实现大范围实时监测。

  2. 成本高:实验室分析需要专业设备和人员,维护费用昂贵。

  3. 实时性差:无法及时预警藻类暴发,延误治理时机。

近年来,基于深度学习的目标检测技术(如YOLO系列)在环境监测领域展现出巨大潜力。YOLOv10作为最新版本,具有更高的检测精度和实时性,非常适合应用于水藻检测场景。本项目旨在利用YOLOv10算法,结合水下图像数据,开发一套智能化的水藻检测系统,为水质管理和生态保护提供技术支持。


项目意义

  1. 提升监测效率:通过AI自动检测,减少人工干预,实现快速、大范围的水藻监测。

  2. 降低监测成本:减少实验室分析依赖,降低设备与人力成本。

  3. 支持生态保护:实时预警藻类异常增殖,助力水体污染治理。

  4. 推动智慧环保:为智慧水务、生态监测等领域提供AI解决方案,推动环境监测智能化发展。

目录

一、项目介绍

项目摘要

项目背景

项目意义

二、项目功能展示

系统功能

图片检测

视频检测

摄像头实时检测

三、数据集介绍

数据集配置文件data.yaml

数据集制作流程

四、项目环境配置

创建虚拟环境

pycharm中配置anaconda

安装所需要库

五、模型训练

训练代码

训练结果

六、核心代码

七、项目源码

(视频下方简介内)


基于深度学习YOLOv10的水藻检测系统(YOLOv10+YOLO数据集+UI界面+Python项目源码+模型)_哔哩哔哩_bilibili

基于深度学习YOLOv10的水藻检测系统(YOLOv10+YOLO数据集+UI界面+Python项目源码+模型)

二、项目功能展示

系统功能

图片检测:可对图片进行检测,返回检测框及类别信息。

视频检测:支持视频文件输入,检测视频中每一帧的情况。

摄像头实时检测:连接USB 摄像头,实现实时监测。

参数实时调节(置信度和IoU阈值)

  • 图片检测

该功能允许用户通过单张图片进行目标检测。输入一张图片后,YOLO模型会实时分析图像,识别出其中的目标,并在图像中框出检测到的目标,输出带有目标框的图像。

  • 视频检测

视频检测功能允许用户将视频文件作为输入。YOLO模型将逐帧分析视频,并在每一帧中标记出检测到的目标。最终结果可以是带有目标框的视频文件或实时展示,适用于视频监控和分析等场景。

  • 摄像头实时检测

该功能支持通过连接摄像头进行实时目标检测。YOLO模型能够在摄像头拍摄的实时视频流中进行目标检测,实时识别并显示检测结果。此功能非常适用于安防监控、无人驾驶、智能交通等应用,提供即时反馈。

核心特点:

  • 高精度:基于YOLO模型,提供精确的目标检测能力,适用于不同类型的图像和视频。
  • 实时性:特别优化的算法使得实时目标检测成为可能,无论是在视频还是摄像头实时检测中,响应速度都非常快。
  • 批量处理:支持高效的批量图像和视频处理,适合大规模数据分析。

三、数据集介绍

数据集名称:水藻检测数据集
类别数量(nc):1类
类别名称

  1. 水藻(Algae)

数据集规模

  • 训练集:704张水下图像(含标注)

  • 验证集:344张水下图像(用于模型调优)

数据集特点

  1. 目标单一:专注于水藻检测,适用于水质监测场景。

  2. 环境复杂:水下图像可能存在光照不均、悬浮物干扰、藻类形态多变等问题,增加检测难度。

  3. 高质量标注:每张图像均标注水藻区域边界框(Bounding Box),确保训练数据准确性。

  4. 真实场景:数据来自不同水域(湖泊、河流、养殖区等),覆盖多种光照和水质条件。

数据集配置文件data.yaml

train: .\datasets\images\train val: .\datasets\images\val test: .\datasets\images\test nc: 1 names: ['水藻']

数据集制作流程

  • 标注数据:使用标注工具(如LabelImg、CVAT等)对图像中的目标进行标注。每个目标需要标出边界框,并且标注类别。

  • 转换格式:将标注的数据转换为YOLO格式。YOLO标注格式为每行:<object-class> <x_center> <y_center> <width> <height>,这些坐标是相对于图像尺寸的比例。

  • 分割数据集:将数据集分为训练集、验证集和测试集,通常的比例是80%训练集、10%验证集和10%测试集。

  • 准备标签文件:为每张图片生成一个对应的标签文件,确保标签文件与图片的命名一致。

  • 调整图像尺寸:根据YOLO网络要求,统一调整所有图像的尺寸(如416x416或608x608)。

四、项目环境配置

创建虚拟环境

首先新建一个Anaconda环境,每个项目用不同的环境,这样项目中所用的依赖包互不干扰。

终端输入

conda create -n yolov10 python==3.9

激活虚拟环境

conda activate yolov10

安装cpu版本pytorch

pip install torch torchvision torchaudio

pycharm中配置anaconda

安装所需要库

pip install -r requirements.txt

五、模型训练

训练代码

from ultralytics import YOLOv10 model_path = 'yolov10s.pt' data_path = 'datasets/data.yaml' if __name__ == '__main__': model = YOLOv10(model_path) results = model.train(data=data_path, epochs=500, batch=64, device='0', workers=0, project='runs/detect', name='exp', )
根据实际情况更换模型 yolov10n.yaml (nano):轻量化模型,适合嵌入式设备,速度快但精度略低。 yolov10s.yaml (small):小模型,适合实时任务。 yolov10m.yaml (medium):中等大小模型,兼顾速度和精度。 yolov10b.yaml (base):基本版模型,适合大部分应用场景。 yolov10l.yaml (large):大型模型,适合对精度要求高的任务。
  • --batch 64:每批次64张图像。
  • --epochs 500:训练500轮。
  • --datasets/data.yaml:数据集配置文件。
  • --weights yolov10s.pt:初始化模型权重,yolov10s.pt是预训练的轻量级YOLO模型。

训练结果

六、核心代码

import sys import cv2 import numpy as np from PyQt5.QtWidgets import QApplication, QMessageBox, QFileDialog from PyQt5.QtCore import QThread, pyqtSignal from ultralytics import YOLOv10 from UiMain import UiMainWindow import time import os class DetectionThread(QThread): frame_received = pyqtSignal(np.ndarray, np.ndarray, list) # 原始帧, 检测帧, 检测结果 finished_signal = pyqtSignal() # 线程完成信号 def __init__(self, model, source, conf, iou, parent=None): super().__init__(parent) self.model = model self.source = source self.conf = conf self.iou = iou self.running = True def run(self): try: if isinstance(self.source, int) or self.source.endswith(('.mp4', '.avi', '.mov')): # 视频或摄像头 cap = cv2.VideoCapture(self.source) while self.running and cap.isOpened(): ret, frame = cap.read() if not ret: break # 保存原始帧 original_frame = frame.copy() # 检测 results = self.model(frame, conf=self.conf, iou=self.iou) annotated_frame = results[0].plot() # 提取检测结果 detections = [] for result in results: for box in result.boxes: class_id = int(box.cls) class_name = self.model.names[class_id] confidence = float(box.conf) x, y, w, h = box.xywh[0].tolist() detections.append((class_name, confidence, x, y)) # 发送信号 self.frame_received.emit( cv2.cvtColor(original_frame, cv2.COLOR_BGR2RGB), cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB), detections ) # 控制帧率 time.sleep(0.03) # 约30fps cap.release() else: # 图片 frame = cv2.imread(self.source) if frame is not None: original_frame = frame.copy() results = self.model(frame, conf=self.conf, iou=self.iou) annotated_frame = results[0].plot() # 提取检测结果 detections = [] for result in results: for box in result.boxes: class_id = int(box.cls) class_name = self.model.names[class_id] confidence = float(box.conf) x, y, w, h = box.xywh[0].tolist() detections.append((class_name, confidence, x, y)) self.frame_received.emit( cv2.cvtColor(original_frame, cv2.COLOR_BGR2RGB), cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB), detections ) except Exception as e: print(f"Detection error: {e}") finally: self.finished_signal.emit() def stop(self): self.running = False class MainWindow(UiMainWindow): def __init__(self): super().__init__() # 初始化模型 self.model = None self.detection_thread = None self.current_image = None self.current_result = None self.video_writer = None self.is_camera_running = False self.is_video_running = False self.last_detection_result = None # 新增:保存最后一次检测结果 # 连接按钮信号 self.image_btn.clicked.connect(self.detect_image) self.video_btn.clicked.connect(self.detect_video) self.camera_btn.clicked.connect(self.detect_camera) self.stop_btn.clicked.connect(self.stop_detection) self.save_btn.clicked.connect(self.save_result) # 初始化模型 self.load_model() def load_model(self): try: model_name = self.model_combo.currentText() self.model = YOLOv10(f"{model_name}.pt") # 自动下载或加载本地模型 self.update_status(f"模型 {model_name} 加载成功") except Exception as e: QMessageBox.critical(self, "错误", f"模型加载失败: {str(e)}") self.update_status("模型加载失败") def detect_image(self): if self.detection_thread and self.detection_thread.isRunning(): QMessageBox.warning(self, "警告", "请先停止当前检测任务") return file_path, _ = QFileDialog.getOpenFileName( self, "选择图片", "", "图片文件 (*.jpg *.jpeg *.png *.bmp)") if file_path: self.clear_results() self.current_image = cv2.imread(file_path) self.current_image = cv2.cvtColor(self.current_image, cv2.COLOR_BGR2RGB) self.display_image(self.original_image_label, self.current_image) # 创建检测线程 conf = self.confidence_spinbox.value() iou = self.iou_spinbox.value() self.detection_thread = DetectionThread(self.model, file_path, conf, iou) self.detection_thread.frame_received.connect(self.on_frame_received) self.detection_thread.finished_signal.connect(self.on_detection_finished) self.detection_thread.start() self.update_status(f"正在检测图片: {os.path.basename(file_path)}") def detect_video(self): if self.detection_thread and self.detection_thread.isRunning(): QMessageBox.warning(self, "警告", "请先停止当前检测任务") return file_path, _ = QFileDialog.getOpenFileName( self, "选择视频", "", "视频文件 (*.mp4 *.avi *.mov)") if file_path: self.clear_results() self.is_video_running = True # 初始化视频写入器 cap = cv2.VideoCapture(file_path) frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) fps = cap.get(cv2.CAP_PROP_FPS) cap.release() # 创建保存路径 save_dir = "results" os.makedirs(save_dir, exist_ok=True) timestamp = time.strftime("%Y%m%d_%H%M%S") save_path = os.path.join(save_dir, f"result_{timestamp}.mp4") fourcc = cv2.VideoWriter_fourcc(*'mp4v') self.video_writer = cv2.VideoWriter(save_path, fourcc, fps, (frame_width, frame_height)) # 创建检测线程 conf = self.confidence_spinbox.value() iou = self.iou_spinbox.value() self.detection_thread = DetectionThread(self.model, file_path, conf, iou) self.detection_thread.frame_received.connect(self.on_frame_received) self.detection_thread.finished_signal.connect(self.on_detection_finished) self.detection_thread.start() self.update_status(f"正在检测视频: {os.path.basename(file_path)}") def detect_camera(self): if self.detection_thread and self.detection_thread.isRunning(): QMessageBox.warning(self, "警告", "请先停止当前检测任务") return self.clear_results() self.is_camera_running = True # 创建检测线程 (默认使用摄像头0) conf = self.confidence_spinbox.value() iou = self.iou_spinbox.value() self.detection_thread = DetectionThread(self.model, 0, conf, iou) self.detection_thread.frame_received.connect(self.on_frame_received) self.detection_thread.finished_signal.connect(self.on_detection_finished) self.detection_thread.start() self.update_status("正在从摄像头检测...") def stop_detection(self): if self.detection_thread and self.detection_thread.isRunning(): self.detection_thread.stop() self.detection_thread.quit() self.detection_thread.wait() if self.video_writer: self.video_writer.release() self.video_writer = None self.is_camera_running = False self.is_video_running = False self.update_status("检测已停止") def on_frame_received(self, original_frame, result_frame, detections): # 更新原始图像和结果图像 self.display_image(self.original_image_label, original_frame) self.display_image(self.result_image_label, result_frame) # 保存当前结果帧用于后续保存 self.last_detection_result = result_frame # 新增:保存检测结果 # 更新表格 self.clear_results() for class_name, confidence, x, y in detections: self.add_detection_result(class_name, confidence, x, y) # 保存视频帧 if self.video_writer: self.video_writer.write(cv2.cvtColor(result_frame, cv2.COLOR_RGB2BGR)) def on_detection_finished(self): if self.video_writer: self.video_writer.release() self.video_writer = None self.update_status("视频检测完成,结果已保存") elif self.is_camera_running: self.update_status("摄像头检测已停止") else: self.update_status("图片检测完成") def save_result(self): if not hasattr(self, 'last_detection_result') or self.last_detection_result is None: QMessageBox.warning(self, "警告", "没有可保存的检测结果") return save_dir = "results" os.makedirs(save_dir, exist_ok=True) timestamp = time.strftime("%Y%m%d_%H%M%S") if self.is_camera_running or self.is_video_running: # 保存当前帧为图片 save_path = os.path.join(save_dir, f"snapshot_{timestamp}.jpg") cv2.imwrite(save_path, cv2.cvtColor(self.last_detection_result, cv2.COLOR_RGB2BGR)) self.update_status(f"截图已保存: {save_path}") else: # 保存图片检测结果 save_path = os.path.join(save_dir, f"result_{timestamp}.jpg") cv2.imwrite(save_path, cv2.cvtColor(self.last_detection_result, cv2.COLOR_RGB2BGR)) self.update_status(f"检测结果已保存: {save_path}") def closeEvent(self, event): self.stop_detection() event.accept() if __name__ == "__main__": app = QApplication(sys.argv) # 设置应用程序样式 app.setStyle("Fusion") # 创建并显示主窗口 window = MainWindow() window.show() sys.exit(app.exec_())

七、项目源码

(视频下方简介内)

完整全部资源文件(包括测试图片、视频,py文件,训练数据集、训练代码、界面代码等),这里已打包上传至博主的平台,见可参考博客与视频,已将所有涉及的文件同时打包到里面,点击即可运行,完整文件截图如下:

基于深度学习YOLOv10的水藻检测系统(YOLOv10+YOLO数据集+UI界面+Python项目源码+模型)_哔哩哔哩_bilibili

基于深度学习YOLOv10的水藻检测系统(YOLOv10+YOLO数据集+UI界面+Python项目源码+模型)

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/16 12:26:31

HTTP 和 HTTPS 的区别(面试常考题),计算机专业学生必备

前言 无论是在校学习还是找工作的时候&#xff0c;老师和面试官都问过同学 HTTP 和 HTTPS 的区别。平时上网的时候也没有关注这个问题&#xff0c;只是知道计算机网络里 HTTP 的概念&#xff0c;所以最近才查资料好好补补这一块。其实这一块的知识延伸很广&#xff0c;如果之前…

作者头像 李华
网站建设 2026/4/1 6:22:31

基于LabVIEW 2018开发的自动化测试系统源码,该系统模仿TestStand编写

基于LabVIEW 2018开发的自动化测试系统源码&#xff0c;该系统模仿TestStand编写&#xff0c;使用者无需花大量时间学习TestStand&#xff0c;直接LabVIEW搭好的框架开发即可。 该源码未用到OOP相关知识&#xff0c;用户也无需熟悉OOP&#xff0c;只需了解状态机编程即可。 该源…

作者头像 李华
网站建设 2026/4/16 12:26:35

对比一圈后,更贴合MBA需求的AI论文写作软件,千笔写作工具 VS 灵感风暴AI

随着人工智能技术的迅猛迭代与普及&#xff0c;AI辅助写作工具已逐步渗透到高校学术写作场景中&#xff0c;成为专科生、本科生、研究生完成毕业论文不可或缺的辅助手段。越来越多面临毕业论文压力的学生&#xff0c;开始依赖各类AI工具简化写作流程、提升创作效率。但与此同时…

作者头像 李华
网站建设 2026/4/9 7:48:17

PDF到Word转换工具

PDF 是共享文档的首选格式。此文件格式旨在创建原始文件的紧凑、完美且无法篡改的版本。但当您想要更改或编辑 PDF 文件时&#xff0c;这是不可能的。在这种情况下&#xff0c;您必须将 PDF 转换为可编辑格式&#xff0c;例如 Word 文档。这就是 PDF 到 Word 转换器发挥作用的地…

作者头像 李华
网站建设 2026/3/25 23:35:38

7.13 多云与混合云部署:跨云平台应用迁移与统一管理方案

7.13 多云与混合云部署:跨云平台应用迁移与统一管理方案 引言 多云和混合云是云原生架构的重要趋势。通过跨云平台部署,可以实现高可用和成本优化。本文将详细介绍多云和混合云的部署方案。 一、多云架构 1.1 架构类型 多区域部署:同一云平台不同区域 多云部署:不同云平…

作者头像 李华
网站建设 2026/4/16 13:03:55

C数据类型本质与应用场景详解

文章目录 C数据类型本质与应用场景详解 一、数据类型本质深度解析 二、核心数据类型本质详解 三、应用场景举例(20个实例) 四、数据类型本质总结 1. 数据类型的三重本质 2. 类型系统的哲学思考 五、编译运行与输出 关键要点总结: 1. 数据类型三大本质 2. 应用场景核心原则 3…

作者头像 李华