Yolov5水果分类识别+pyqt交互式界面

Yolov5 Fruits Detector

  • Yolov5 是一种先进的目标检测算法,可以应用于水果分类识别任务。结合 PyQT
    框架,可以创建一个交互式界面,使用户能够方便地上传图片并获取水果分类结果。以下将详细阐述 Yolov5 水果分类识别和 PyQT
    交互式界面的实现。
  • Yolov5 是由 Ultralytics
    公司开发的一种基于深度学习的目标检测算法,它采用了一种称为单阶段目标检测的方法,具有高准确率和实时性的特点。在水果分类识别任务中,Yolov5
    可以检测图像中的水果,并将其分类为不同的类别,例如苹果、香蕉、橙子等。
  • 为了实现 Yolov5 水果分类识别的交互式界面,可以使用 PyQT 框架进行开发。PyQT 是一个功能强大且易于使用的 Python
    GUI 开发工具包,它提供了丰富的界面组件和布局选项,可以轻松创建用户友好的界面。
  • 在界面设计方面,可以使用 PyQT 创建一个包含上传图片按钮和显示分类结果的窗口。当用户点击上传图片按钮时,可以调用 Yolov5
    模型对上传的图片进行识别,并将分类结果显示在界面上。同时,还可以添加其他功能,如清除界面、保存结果等。

要求

  • 可以使用 Linux 或者 Windows。我们推荐使用 Linux 以获得更好的性能。
  • 需要安装 Python 3.6+ 和 PyTorch 1.7+。

安装

运行以下命令来安装依赖项:

复制代码
pip install -r requirements.txt
  • 下载模型,请使用此链接:https://drive.google.com/file/d/1W6qZeutnqnp3YX9w4iYgR44xsoi_64ff/view?usp=sharing
  • 将下载的文件放置在 weights 目录下

代码

运行此部分检测ui界面代码

复制代码
import sys
import os

from PySide6.QtWidgets import QApplication, QWidget, QFileDialog
from PySide6.QtCore import QFile
from PySide6.QtUiTools import QUiLoader
from PySide6.QtGui import QPixmap, QImage
from PySide6.QtCore import QThread, Signal, QDir
import cv2


def convertCVImage2QtImage(cv_img):
    cv_img = cv2.cvtColor(cv_img, cv2.COLOR_BGR2RGB)
    height, width, channel = cv_img.shape
    bytesPerLine = 3 * width
    qimg = QImage(cv_img.data, width, height, bytesPerLine, QImage.Format_RGB888)
    return QPixmap.fromImage(qimg)


class ProcessImage(QThread):
    signal_show_frame = Signal(object)

    def __init__(self, fileName):
        QThread.__init__(self)
        self.fileName = fileName

        from detector import Detector
        self.detector = Detector()

    def run(self):
        self.video = cv2.VideoCapture(self.fileName)
        while True:
            valid, self.frame = self.video.read()
            if valid is not True:
                break
            self.frame = self.detector.detect(self.frame)
            self.signal_show_frame.emit(self.frame)
            cv2.waitKey(30)
        self.video.release()

    def stop(self):
        try:
            self.video.release()
        except:
            pass


class show(QThread):
    signal_show_image = Signal(object)

    def __init__(self, fileName):
        QThread.__init__(self)
        self.fileName = fileName
        self.video=cv2.VideoCapture(self.fileName)

    def run(self): 
        while True:
            valid, self.frame = self.video.read()
            if valid is not True:
                break
            self.signal_show_image.emit(self.frame)
            cv2.waitKey(30)
        self.video.release()

    def stop(self):
        try:
            self.video.release()
        except:
            pass


class MainWindow(QWidget):
    def __init__(self):
        super(MainWindow, self).__init__()
        loader = QUiLoader()
        self.ui = loader.load("ui/form.ui")
        
        self.ui.btn_browse.clicked.connect(self.getFile)
        self.ui.btn_start.clicked.connect(self.predict)

        self.ui.show()

    def getFile(self):
        self.fileName = QFileDialog.getOpenFileName(self,'Single File','C:\'','*.jpg *.mp4 *.jpeg *.png *.avi')[0]
        self.ui.txt_address.setText(str(self.fileName))
        self.show=show(self.fileName)
        self.show.signal_show_image.connect(self.show_input)
        self.show.start()
        
        
    def predict(self):
        self.process_image = ProcessImage(self.fileName)
        self.process_image.signal_show_frame.connect(self.show_output)
        self.process_image.start()

    def show_input(self, image):
        pixmap = convertCVImage2QtImage(image)
        self.ui.lbl_input.setPixmap(pixmap)

    def show_output(self, image):
        pixmap = convertCVImage2QtImage(image)
        self.ui.lbl_output.setPixmap(pixmap)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = MainWindow()
    sys.exit(app.exec())

运行界面

要对图像或视频进行推断,请运行以下命令:

复制代码
python main.py 

数据集:

  • 数据集可以在此链接中找到https://t.ly/NZWj
  • 在 Yolov5 水果分类识别的实现过程中,需要使用训练好的 Yolov5 模型来进行目标检测和分类。可以使用已经预训练好的 Yolov5 模型,也可以自己训练一个适用于水果分类的模型。

总结

总结起来,Yolov5 水果分类识别结合 PyQT 交互式界面可以提供一个方便用户上传图片并获取水果分类结果的工具。Yolov5 算法具有高准确率和实时性,在水果分类任务中表现出色。PyQT 框架提供了丰富的界面组件和布局选项,使得界面开发更加简单。通过 Yolov5 水果分类识别和 PyQT 交互式界面的结合,用户可以轻松地进行水果分类识别,并获得准确的分类结果。

相关推荐
wh_xia_jun14 小时前
基础分类模型及回归简介(一)
分类·数据挖掘·回归
一勺汤15 小时前
多尺度频率辅助类 Mamba 线性注意力模块(MFM),融合频域和空域特征,提升多尺度、复杂场景下的目标检测能力
深度学习·yolo·yolov12·yolo12·yolo12改进·小目标·mamba like
格林威1 天前
Baumer工业相机堡盟工业相机如何通过YoloV8模型实现人物识别(C#)
开发语言·人工智能·数码相机·yolo·计算机视觉·c#
Virgil1391 天前
数据分布是如何影响目标检测精度的
人工智能·深度学习·yolo·目标检测·计算机视觉
李昊哲小课1 天前
K近邻算法的分类与回归应用场景
python·机器学习·分类·数据挖掘·回归·近邻算法·sklearn
灵智工坊LingzhiAI2 天前
使用YOLOv11实现水果类别检测:从数据到模型训练的全过程
yolo
摸鱼仙人~2 天前
现代人工智能综合分类:大模型时代的架构、模态与生态系统
人工智能·分类·数据挖掘
麻雀无能为力2 天前
CAU数据挖掘第四章 分类问题
人工智能·分类·数据挖掘·中国农业大学计算机
lucky_lyovo2 天前
卷积神经网络-卷积的分类
深度学习·分类·cnn
云空2 天前
《PyQtGraph例子库:Python数据可视化的宝藏地图》
开发语言·python·信息可视化·scikit-learn·pyqt