身体的艺术,灵魂的共鸣:探索“操一操”的深层魅力
项目介绍摘要本项目采用先进的YOLOv8深度学习框架开发了一套针对草莓果实病害的高精度智能检测系统。
系统能够准确识别五种关键状态[Benh cao su(橡胶病)、Benh dom den(炭疽病)、Benh moc xam(灰霉病)、Benh phan trang(白粉病)、Qua binh thuong(正常果实)]。
基于包含700张训练图像、81张验证图像和103张测试图像的专业数据集本系统实现了对草莓果实健康状况的快速、自动化诊断。
该系统创新性地将目标检测技术应用于草莓病害识别领域通过深度学习算法提取病害的视觉特征实现了对多种常见草莓病害的精准分类。
本项目的实施将显著提升草莓种植的病害管理水平为智慧农业发展提供有力技术支持。
项目意义
提高病害识别效率保障草莓产业效益传统草莓病害诊断依赖农技人员经验判断效率低下且容易误诊。
本系统可在短时间内完成大面积草莓园的病害筛查检测速度较人工提升几十倍帮助种植者及时发现病害采取针对性防治措施有效降低经济损失。
精准识别多种病害实现科学防治系统能够准确区分橡胶病、炭疽病、灰霉病和白粉病等主要草莓病害基于精准诊断结果种植者可选择最有效的防治方案避免盲目用药既降低生产成本又减少农药残留。
早期病害预警预防大规模爆发系统特别擅长识别灰霉病(Benh moc xam)等病害的初期症状这些症状人眼难以察觉但传播迅速。
通过定期自动检测可在病害扩散前发出预警帮助种植者及时采取隔离措施防止病害蔓延。
促进绿色种植提升果品质量本系统提供的精准病害诊断可指导种植者合理使用生物农药减少化学农药使用量既保护生态环境又提高草莓品质增强市场竞争力助力绿色农业发展。
推动智慧农业转型实现精准种植本系统是人工智能技术在草莓种植领域的创新应用可与农业物联网、自动喷灌系统等智能设备联动构建智慧农业管理平台推动传统种植模式向数字化、智能化方向转型。
弥补农技人员不足服务小型种植户我国草莓种植分布广泛但专业农技人员短缺。
系统操作简便普通种植者经过简单培训即可使用有效解决了小型种植户看病难的问题特别适合在偏远地区推广应用。
建立病害数据库支撑农业科研系统运行积累的检测数据可为农业科研机构提供宝贵的病害流行学研究资料帮助农业部门掌握病害发生规律制定科学的防控策略。
技术特点多病害并行检测采用改进的特征金字塔网络同时识别橡胶病、炭疽病等五种不同病害满足实际种植需求。
小样本高效学习在训练数据有限的情况下通过迁移学习和数据增强技术确保模型具有良好的泛化能力。
轻量化设计对YOLOv8模型进行优化使其可在手机等移动设备上流畅运行适应田间使用环境。
抗干扰能力强能够有效区分病害症状与正常生理变化避免光照条件、果实成熟度等因素的干扰。
应用前景本系统可广泛应用于草莓种植园的日常病害监测种苗繁育基地的健康筛查农业技术推广站的诊断服务水果收购商的质量检测农业科研机构的病害研究农业保险公司的风险评估农产品质量安全监管
总结本项目的YOLOv8草莓病害智能检测系统将人工智能技术与农业生产实际需求相结合有效解决了草莓种植中的病害识别难题。
系统不仅提高了病害检测的效率和准确性还促进了种植模式的智能化转型推动了农业高质量发展。
随着系统的不断完善和推广应用创造显著的经济效益和生态效益。
未来我们将继续扩充病害识别种类提升系统性能为现代农业发展作出更大贡献。
基于深度学习的草莓果实病害检测系统YOLOv8YOLO数据集UI界面Python项目源码模型_哔哩哔哩_bilibili基于深度学习的草莓果实病害检测系统YOLOv8YOLO数据集UI界面Python项目源码模型
项目功能展示系统功能✅图片检测可对单张图片进行检测返回检测框及类别信息。
✅批量图片检测支持文件夹输入一次性检测多张图片生成批量检测结果。
✅视频检测支持视频文件输入检测视频中每一帧的情况。
✅摄像头实时检测连接USB 摄像头实现实时监测图片检测该功能允许用户通过单张图片进行目标检测。
输入一张图片后YOLO模型会实时分析图像识别出其中的目标并在图像中框出检测到的目标输出带有目标框的图像。
批量图片检测用户可以一次性上传多个图片进行批量处理。
该功能支持对多个图像文件进行并行处理并返回每张图像的目标检测结果适用于需要大规模处理图像数据的应用场景。
视频检测视频检测功能允许用户将视频文件作为输入。
YOLO模型将逐帧分析视频并在每一帧中标记出检测到的目标。
最终结果可以是带有目标框的视频文件或实时展示适用于视频监控和分析等场景。
摄像头实时检测该功能支持通过连接摄像头进行实时目标检测。
YOLO模型能够在摄像头拍摄的实时视频流中进行目标检测实时识别并显示检测结果。
此功能非常适用于安防监控、无人驾驶、智能交通等应用提供即时反馈。
核心特点高精度基于YOLO模型提供精确的目标检测能力适用于不同类型的图像和视频。
实时性特别优化的算法使得实时目标检测成为可能无论是在视频还是摄像头实时检测中响应速度都非常快。
批量处理支持高效的批量图像和视频处理适合大规模数据分析。
数据集介绍数据集概述本项目的数据集包含五类标签Benh cao su橡胶病、Benh dom den黑斑病、Benh moc xam灰霉病、Benh phan trang白粉病、Qua binh thuong正常果实。
数据集分为训练集、验证集和测试集数据集结构数据集中的每张图像都经过标注标注信息包括类别标签Benh cao su、Benh dom den、Benh moc xam、Benh phan trang、Qua binh thuong边界框坐标病害区域的位置信息x_min, y_min, x_max, y_max数据来源数据集来源于公开的农业病害数据库或合作种植园提供的草莓图像数据。
所有数据均经过专业人员的标注和审核确保标注的准确性。
数据预处理图像增强为了提升模型的泛化能力对训练集进行了数据增强操作包括随机旋转、翻转、缩放、亮度调整等。
归一化将所有图像归一化到相同的尺寸如640x640以适应YOLOv8的输入要求。
标注格式转换将标注信息转换为YOLOv8所需的格式类别索引、归一化的边界框坐标。
数据集特点类别多样性数据集涵盖了四种常见的草莓病害和正常果实能够满足实际种植中的病害检测需求。
高质量标注所有标注均由专业人员完成确保标注的准确性和可靠性。
样本分布训练集、验证集和测试集的划分合理确保模型训练和评估的科学性。
数据集划分训练集用于训练YOLOv8模型优化模型参数。
验证集用于调整超参数和评估模型在训练过程中的表现防止过拟合。
测试集用于最终评估模型的性能确保模型在未见数据上的泛化能力。
数据集配置文件data.yamltrain: .\datasets\images\train val: .\datasets\images\val test: .\datasets\images\test # Classes nc: 6 # class names names: [ hand-raising, reading, writing,using phone, bowing the head, leaning over the table]数据集制作流程标注数据使用标注工具如LabelImg、CVAT等对图像中的目标进行标注。
每个目标需要标出边界框并且标注类别。
转换格式将标注的数据转换为YOLO格式。
YOLO标注格式为每行object-class x_center y_center width height这些坐标是相对于图像尺寸的比例。
分割数据集将数据集分为训练集、验证集和测试集通常的比例是80%训练集、10%验证集和10%测试集。
准备标签文件为每张图片生成一个对应的标签文件确保标签文件与图片的命名一致。
调整图像尺寸根据YOLO网络要求统一调整所有图像的尺寸如416x416或608x608。
项目环境配置创建虚拟环境首先新建一个Anaconda环境每个项目用不同的环境这样项目中所用的依赖包互不干扰。
终端输入conda create -n yolov8 python
9激活虚拟环境conda activate yolov8安装cpu版本pytorchpip install torch torchvision torchaudiopycharm中配置anaconda安装所需要库pip install -r requirements.txt
模型训练训练代码from ultralytics import YOLO model_path yolov8s.pt data_path datasets/data.yaml if __name__ __main__: model YOLO(model_path) results model.train(datadata_path, epochs500, batch64, device0, workers0, projectruns/detect, nameexp, )根据实际情况更换模型 yolov8n.yaml (nano)轻量化模型适合嵌入式设备速度快但精度略低。
yolov8s.yaml (small)小模型适合实时任务。
yolov8m.yaml (medium)中等大小模型兼顾速度和精度。
yolov8b.yaml (base)基本版模型适合大部分应用场景。
yolov8l.yaml (large)大型模型适合对精度要求高的任务。
--batch 64每批次64张图像。
--epochs 500训练500轮。
--datasets/data.yaml数据集配置文件。
--weights yolov8s.pt初始化模型权重yolov8s.pt是预训练的轻量级YOLO模型。
训练结果
核心代码# -*- coding: utf-8 -*- import os import sys import time import cv2 import numpy as np from PIL import ImageFont from PyQt
QtCore import Qt, QTimer, QThread, pyqtSignal, QCoreApplication from PyQt
QtWidgets import (QApplication, QMainWindow, QFileDialog, QMessageBox, QWidget, QHeaderView, QTableWidgetItem, QAbstractItemView) from ultralytics import YOLO # 自定义模块导入 sys.path.append(UIProgram) from UIProgram.UiMain import Ui_MainWindow from UIProgram.QssLoader import QSSLoader from UIProgram.precess_bar import ProgressBar import detect_tools as tools import Config class DetectionApp(QMainWindow): def __init__(self, parentNone): super().__init__(parent) self.ui Ui_MainWindow() self.ui.setupUi(self) # 初始化应用 self._setup_ui() self._connect_signals() self._load_stylesheet() # 模型和资源初始化 self._init_detection_resources() def _setup_ui(self): 初始化UI界面设置 self.display_width 700 self.display_height 500 self.source_path None self.camera_active False self.video_capture None # 配置表格控件 table self.ui.tableWidget table.verticalHeader().setSectionResizeMode(QHeaderView.Fixed) table.verticalHeader().setDefaultSectionSize(
table.setColumnWidth(0,
# ID列 table.setColumnWidth(1,
# 路径列 table.setColumnWidth(2,
# 类别列 table.setColumnWidth(3,
# 置信度列 table.setColumnWidth(4,
# 位置列 table.setSelectionBehavior(QAbstractItemView.SelectRows) table.verticalHeader().setVisible(False) table.setAlternatingRowColors(True) def _connect_signals(self): 连接按钮信号与槽函数 self.ui.PicBtn.clicked.connect(self._handle_image_input) self.ui.comboBox.activated.connect(self._update_selection) self.ui.VideoBtn.clicked.connect(self._handle_video_input) self.ui.CapBtn.clicked.connect(self._toggle_camera) self.ui.SaveBtn.clicked.connect(self._save_results) self.ui.ExitBtn.clicked.connect(QCoreApplication.quit) self.ui.FilesBtn.clicked.connect(self._process_image_batch) def _load_stylesheet(self): 加载CSS样式表 style_file UIProgram/style.css qss QSSLoader.read_qss_file(style_file) self.setStyleSheet(qss) def _init_detection_resources(self): 初始化检测相关资源 # 加载YOLOv8模型 self.detector YOLO(runs/detect/exp/weights/best.pt, taskdetect) self.detector(np.zeros((48, 48,
)) # 预热模型 # 初始化字体和颜色 self.detection_font ImageFont.truetype(Font/platech.ttf, 25,
self.color_palette tools.Colors() # 初始化定时器 self.frame_timer QTimer() self.save_timer QTimer() def _handle_image_input(self): 处理单张图片输入 self._stop_video_capture() file_path, _ QFileDialog.getOpenFileName( self, 选择图片, ./, 图片文件 (*.jpg *.jpeg *.png)) if not file_path: return self._process_single_image(file_path) def _process_single_image(self, image_path): 处理并显示单张图片的检测结果 self.source_path image_path self.ui.comboBox.setEnabled(True) # 读取并检测图片 start_time time.time() detection_results self.detector(image_path)[0] processing_time time.time() - start_time # 解析检测结果 boxes detection_results.boxes.xyxy.tolist() self.detection_boxes [list(map(int, box)) for box in boxes] self.detection_classes detection_results.boxes.cls.int().tolist() confidences detection_results.boxes.conf.tolist() self.confidence_scores [f{score * 100:.2f}% for score in confidences] # 更新UI显示 self._update_detection_display(detection_results, processing_time) self._update_object_selection() self._show_detection_details() self._display_results_table(image_path) def _update_detection_display(self, results, process_time): 更新检测结果显示 # 显示处理时间 self.ui.time_lb.setText(f{process_time:.3f} s) # 获取带标注的图像 annotated_img results.plot() self.current_result annotated_img # 调整并显示图像 width, height self._calculate_display_size(annotated_img) resized_img cv
resize(annotated_img, (width, height)) qimage tools.cvimg_to_qpiximg(resized_img) self.ui.label_show.setPixmap(qimage) self.ui.label_show.setAlignment(Qt.AlignCenter) self.ui.PiclineEdit.setText(self.source_path) # 更新检测数量 self.ui.label_nums.setText(str(len(self.detection_classes))) def _calculate_display_size(self, image): 计算适合显示的图像尺寸 img_height, img_width image.shape[:2] aspect_ratio img_width / img_height if aspect_ratio self.display_width / self.display_height: width self.display_width height int(width / aspect_ratio) else: height self.display_height width int(height * aspect_ratio) return width, height def _update_object_selection(self): 更新目标选择下拉框 options [全部] target_labels [ f{Config.names[cls_id]}_{idx} for idx, cls_id in enumerate(self.detection_classes) ] options.extend(target_labels) self.ui.comboBox.clear() self.ui.comboBox.addItems(options) def _show_detection_details(self, index
: 显示检测目标的详细信息 if not self.detection_boxes: self._clear_detection_details() return box self.detection_boxes[index] self.ui.type_lb.setText(Config.CH_names[self.detection_classes[index]]) self.ui.label_conf.setText(self.confidence_scores[index]) self.ui.label_xmin.setText(str(box[0])) self.ui.label_ymin.setText(str(box[1])) self.ui.label_xmax.setText(str(box[2])) self.ui.label_ymax.setText(str(box[3])) def _clear_detection_details(self): 清空检测详情显示 self.ui.type_lb.setText() self.ui.label_conf.setText() self.ui.label_xmin.setText() self.ui.label_ymin.setText() self.ui.label_xmax.setText() self.ui.label_ymax.setText() def _display_results_table(self, source_path): 在表格中显示检测结果 table self.ui.tableWidget table.setRowCount(
table.clearContents() for idx, (box, cls_id, conf) in enumerate(zip( self.detection_boxes, self.detection_classes, self.confidence_scores)): row table.rowCount() table.insertRow(row) # 添加表格项 items [ QTableWidgetItem(str(row
), # ID QTableWidgetItem(source_path), # 路径 QTableWidgetItem(Config.CH_names[cls_id]), # 类别 QTableWidgetItem(conf), # 置信度 QTableWidgetItem(str(box)) # 位置坐标 ] # 设置文本居中 for item in [items[0], items[2], items[3]]: item.setTextAlignment(Qt.AlignCenter) # 添加到表格 for col, item in enumerate(items): table.setItem(row, col, item) table.scrollToBottom() def _process_image_batch(self): 批量处理图片 self._stop_video_capture() folder QFileDialog.getExistingDirectory(self, 选择图片文件夹, ./) if not folder: return self.source_path folder valid_extensions {jpg, png, jpeg, bmp} for filename in os.listdir(folder): filepath os.path.join(folder, filename) if (os.path.isfile(filepath) and filename.split(.)[-1].lower() in valid_extensions): self._process_single_image(filepath) QApplication.processEvents() # 保持UI响应 def _update_selection(self): 更新用户选择的检测目标显示 selection self.ui.comboBox.currentText() if selection 全部: boxes self.detection_boxes display_img self.current_result self._show_detection_details(
else: idx int(selection.split(_)[-1]) boxes [self.detection_boxes[idx]] display_img self.detector(self.source_path)[0][idx].plot() self._show_detection_details(idx) # 更新显示 width, height self._calculate_display_size(display_img) resized_img cv
resize(display_img, (width, height)) qimage tools.cvimg_to_qpiximg(resized_img) self.ui.label_show.clear() self.ui.label_show.setPixmap(qimage) self.ui.label_show.setAlignment(Qt.AlignCenter) def _handle_video_input(self): 处理视频输入 if self.camera_active: self._toggle_camera() video_path self._get_video_path() if not video_path: return self._start_video_processing(video_path) self.ui.comboBox.setEnabled(False) def _get_video_path(self): 获取视频文件路径 path, _ QFileDialog.getOpenFileName( self, 选择视频, ./, 视频文件 (*.avi *.mp
) if path: self.source_path path self.ui.VideolineEdit.setText(path) return path return None def _start_video_processing(self, video_path): 开始处理视频流 self.video_capture cv
VideoCapture(video_path) self.frame_timer.start(
self.frame_timer.timeout.connect(self._process_video_frame) def _stop_video_capture(self): 停止视频捕获 if self.video_capture: self.video_capture.release() self.frame_timer.stop() self.camera_active False self.ui.CaplineEdit.setText(摄像头未开启) self.video_capture None def _process_video_frame(self): 处理视频帧 ret, frame self.video_capture.read() if not ret: self._stop_video_capture() return # 执行目标检测 start_time time.time() results self.detector(frame)[0] processing_time time.time() - start_time # 解析结果 self.detection_boxes results.boxes.xyxy.int().tolist() self.detection_classes results.boxes.cls.int().tolist() self.confidence_scores [f{conf * 100:.2f}% for conf in results.boxes.conf.tolist()] # 更新显示 self._update_detection_display(results, processing_time) self._update_object_selection() self._show_detection_details() self._display_results_table(self.source_path) def _toggle_camera(self): 切换摄像头状态 self.camera_active not self.camera_active if self.camera_active: self.ui.CaplineEdit.setText(摄像头开启) self.video_capture cv
VideoCapture(
self._start_video_processing(
self.ui.comboBox.setEnabled(False) else: self.ui.CaplineEdit.setText(摄像头未开启) self.ui.label_show.clear() self._stop_video_capture() def _save_results(self): 保存检测结果 if not self.video_capture and not self.source_path: QMessageBox.information(self, 提示, 没有可保存的内容请先打开图片或视频) return if self.camera_active: QMessageBox.information(self, 提示, 无法保存摄像头实时视频) return if self.video_capture: self._save_video_result() else: self._save_image_result() def _save_video_result(self): 保存视频检测结果 confirm QMessageBox.question( self, 确认, 保存视频可能需要较长时间确定继续吗, QMessageBox.Yes | QMessageBox.No) if confirm QMessageBox.No: return self._stop_video_capture() saver VideoSaverThread( self.source_path, self.detector, self.ui.comboBox.currentText()) saver.start() saver.update_ui_signal.connect(self._update_progress) def _save_image_result(self): 保存图片检测结果 if os.path.isfile(self.source_path): # 处理单张图片 filename os.path.basename(self.source_path) name, ext filename.rsplit(.,
save_name f{name}_detect_result.{ext} save_path os.path.join(Config.save_path, save_name) cv
imwrite(save_path, self.current_result) QMessageBox.information( self, 完成, f图片已保存至: {save_path}) else: # 处理文件夹中的图片 valid_exts {jpg, png, jpeg, bmp} for filename in os.listdir(self.source_path): if filename.split(.)[-1].lower() in valid_exts: filepath os.path.join(self.source_path, filename) name, ext filename.rsplit(.,
save_name f{name}_detect_result.{ext} save_path os.path.join(Config.save_path, save_name) results self.detector(filepath)[0] cv
imwrite(save_path, results.plot()) QMessageBox.information( self, 完成, f所有图片已保存至: {Config.save_path}) def _update_progress(self, current, total): 更新保存进度 if current 1: self.progress_dialog ProgressBar(self) self.progress_dialog.show() if current total: self.progress_dialog.close() QMessageBox.information( self, 完成, f视频已保存至: {Config.save_path}) return if not self.progress_dialog.isVisible(): return percent int(current / total *
self.progress_dialog.setValue(current, total, percent) QApplication.processEvents() class VideoSaverThread(QThread): 视频保存线程 update_ui_signal pyqtSignal(int, int) def __init__(self, video_path, model, selection): super().__init__() self.video_path video_path self.detector model self.selection selection self.active True self.colors tools.Colors() def run(self): 执行视频保存 cap cv
VideoCapture(self.video_path) fourcc cv
VideoWriter_fourcc(*XVID) fps cap.get(cv
CAP_PROP_FPS) size ( int(cap.get(cv
CAP_PROP_FRAME_WIDTH)), int(cap.get(cv
CAP_PROP_FRAME_HEIGHT))) filename os.path.basename(self.video_path) name, _ filename.split(.) save_path os.path.join( Config.save_path, f{name}_detect_result.avi) writer cv
VideoWriter(save_path, fourcc, fps, size) total_frames int(cap.get(cv
CAP_PROP_FRAME_COUNT)) current_frame 0 while cap.isOpened() and self.active: current_frame 1 ret, frame cap.read() if not ret: break # 执行检测 results self.detector(frame)[0] frame results.plot() writer.write(frame) self.update_ui_signal.emit(current_frame, total_frames) # 释放资源 cap.release() writer.release() def stop(self): 停止保存过程 self.active False if __name__ __main__: app QApplication(sys.argv) window DetectionApp() window.show() sys.exit(app.exec_())
项目演示与介绍视频基于深度学习的草莓果实病害检测系统YOLOv8YOLO数据集UI界面Python项目源码模型_哔哩哔哩_bilibili基于深度学习的草莓果实病害检测系统YOLOv8YOLO数据集UI界面Python项目源码模型
4虎cvt4wd入口免费版特色cvt-4虎cvt4wd入口免费版特色应用