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

基于深度学习的苹果新鲜度检测系统(YOLOv10+YOLO数据集+UI界面+模型)

一、项目介绍

YOLOv10苹果检测系统是一个基于YOLOv10(You Only Look Once version 10)目标检测算法的智能系统,专门用于检测和分类苹果的状态。该系统能够自动识别苹果并将其分类为两类:apple(正常苹果)damaged_apple(受损苹果)。通过该系统,用户可以快速检测苹果的质量状态,适用于果园采摘、水果分拣、质量检测等场景,帮助提高生产效率并减少人工成本。

该系统在农业自动化、水果分拣、食品质量检测等领域具有广泛的应用前景,能够为用户提供高效、准确的苹果状态检测解决方案。

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

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

二、项目功能展示

系统功能

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

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

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

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

  • 图片检测

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

用户可以一次性上传多个图片进行批量处理。该功能支持对多个图像文件进行并行处理,并返回每张图像的目标检测结果,适用于需要大规模处理图像数据的应用场景。

视频检测

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

  • 摄像头实时检测

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

核心特点:

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

三、数据集介绍

数据集名称: 苹果检测数据集
数据集类别: 2类
类别名称: ['apple', 'damaged_apple']

数据集划分:

  • 训练集:
    训练集用于训练YOLOv10模型,使其能够学习并识别正常苹果和受损苹果的特征。训练集的图像涵盖了不同光照条件、背景环境以及苹果的不同状态,以确保模型的泛化能力。

  • 验证集:
    验证集用于在训练过程中评估模型的性能,帮助调整超参数和防止过拟合。验证集的图像与训练集类似,但独立于训练集,确保模型在未见过的数据上也能表现良好。

  • 测试集:
    测试集用于最终评估模型的性能,反映模型在实际应用中的表现。测试集的图像是完全独立的,确保评估结果的客观性和准确性。

数据集特点:

  • 高质量标注: 每张图像都经过精确的标注,标注信息包括苹果的类别(正常或受损)和边界框位置,确保模型能够准确学习目标特征。

  • 多样性: 数据集中的图像涵盖了不同光照条件、背景环境以及苹果的不同状态(如轻微损伤、严重损伤等),确保模型能够适应各种实际场景。

  • 类别平衡: 数据集中正常苹果和受损苹果的样本数量相对平衡,避免了类别不平衡问题对模型性能的影响。

应用场景:

  • 果园采摘: 在果园中实时检测苹果的状态,帮助果农快速区分正常苹果和受损苹果,优化采摘流程。

  • 水果分拣: 在水果加工厂中,系统可以自动分拣正常苹果和受损苹果,提高分拣效率并减少人工成本。

  • 食品质量检测: 在食品供应链中,系统可以用于检测苹果的质量状态,确保只有高质量的苹果进入市场。

训练集

验证集

数据集配置文件data.yaml

train: .\datasets\images\train val: .\datasets\images\val test: .\datasets\images\test nc: 2 names: ['apple', 'damaged_apple']

数据集制作流程

  • 标注数据:使用标注工具(如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_())

七、项目

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

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

http://www.jsqmd.com/news/263473/

相关文章:

  • 2026年国内做得好的离婚律师机构找哪家,北京继承律师哪个好/离婚纠纷律师/北京丰台离婚律师,离婚律师机构推荐榜单 - 品牌推荐师
  • 多模态大模型架构深度解析:模块化vs原生架构工作原理全解析
  • 编写一个Buildroot 内核驱动
  • 基于深度学习的冰箱内食物检测系统(YOLOv10+YOLO数据集+UI界面+模型)
  • AI产品经理思维框架:从技术小白到商业落地的实战指南
  • 大模型技术全景图:从理论到应用,一篇全掌握!建议收藏
  • 课程论文别再凑字数!宏智树 AI 教你高效写出高分范文
  • 基于深度学习的苹果腐烂检测系统(YOLOv10+YOLO数据集+UI界面+模型)
  • 哈希表解决两数之和
  • 还在手动拼问卷?宏智树 AI:一键搞定实证研究的 “黄金调研工具”
  • 传统产品经理转型AI PM的完整指南,非常详细收藏我这一篇就够了
  • 基于深度学习的树上苹果检测系统(YOLOv10+YOLO数据集+UI界面+模型)
  • 基于深度学习的奶牛行为检测系统(YOLOv10+YOLO数据集+UI界面+模型)
  • 数据不会说话?宏智树 AI:论文数据分析的 “智能翻译官”
  • DeepSeek V4 vs Kimi K3:国产AI大模型技术对决,谁将引领春节前的新爆发?
  • ROS1 noetic 中将 Unitree G1 基于 Gazebo/RViz 关节联动【基于 ros_control】
  • AI 写论文哪个软件最好?实测揭秘!宏智树 AI 凭 “真研究” 实力领跑
  • 基于深度学习的食物检测系统(YOLOv10+YOLO数据集+UI界面+模型)
  • 救命神器!8款AI论文工具测评:本科生毕业论文全攻略
  • 零基础也能入门:AI产品经理高薪职业发展路径全解析,三步成为AI产品经理
  • 大模型产品经理工作全解析:从启动到衍生的评估体系方法论
  • AWS Machine Learning Specialty 证书备考经验
  • 2025年泳池除湿机口碑企业排名,这几家值得信赖,泳池除湿机企业哪里有普沃泰专注产品质量 - 品牌推荐师
  • AI大模型就业实战营:程序员必学,薪资涨幅超50%,职场竞争力飙升!
  • 智能体化AI实战:网络安全领域的新一代技术革命与必备技能
  • 企业级AI基础设施架构:应对大模型混战的模型无关设计指南
  • 企业闲置名酒变现!北京上门回收茅台五粮液,京城亚南专属服务 - 品牌排行榜单
  • 收藏必备!AI产品经理转型指南:从迷茫到高薪,3步搞定大模型时代最值得All in岗位
  • 2026必备!研究生论文写作TOP8一键生成论文工具测评
  • 三色球问题