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 交互式界面的结合,用户可以轻松地进行水果分类识别,并获得准确的分类结果。

相关推荐
m沐沐1 天前
【自然语言处理】词向量转换与中文文本情感分类——从CountVectorizer到朴素贝叶斯
人工智能·算法·机器学习·自然语言处理·分类·中文分词·词向量转换
探物 AI1 天前
yolo核心组件9:BiFPN 加权双向特征金字塔
yolo
懷淰メ2 天前
【AI赋能】基于PyQt+YOLO+DeepSeek水上漂浮物检测系统(详细介绍)
人工智能·yolo·目标检测·计算机视觉·pyqt·漂浮物·水上漂浮物
FL16238631292 天前
非机动车闯红灯电动摩托车闯红灯检测数据集VOC+YOLO格式1754张3类别
人工智能·yolo·机器学习
星云_byto2 天前
开付费专栏的意见收集
yolo·detr·多模态融合·rgb-d·多模态目标检测·rgb-ir·rgb-t
段一凡-华北理工大学2 天前
AI推动工业智能化转型~系列文章07:分类与诊断算法体系:故障识别的完整工具箱
数据库·人工智能·算法·机器学习·分类·数据挖掘·高炉炼铁智能化
酷在前行2 天前
【R模型】R语言随机森林分类进阶:交叉验证、调参与独立测试(保姆级教程)
随机森林·分类·r语言
梦想三三3 天前
YOLOv5 口罩目标检测实战(一):项目整体介绍与数据准备
人工智能·yolo·目标检测
西西弗Sisyphus3 天前
部署模型的优化:图像标准化预处理从三步到一步乘加(2)
人工智能·机器学习·分类·训练·推理·imagenet
hai3152475434 天前
十种编程语言的概率统计视角分析:统计对象分类与统计编程
人工智能·分类·数据挖掘