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

相关推荐
蹦蹦跳跳真可爱5896 小时前
Python----目标检测(使用YOLO 模型进行线程安全推理和流媒体源)
人工智能·python·yolo·目标检测·目标跟踪
蹦蹦跳跳真可爱5898 小时前
Python----目标检测(训练YOLOV8网络)
人工智能·python·yolo·目标检测
孤独野指针*P15 小时前
释放模型潜力:浅谈目标检测微调技术(Fine-tuning)
人工智能·深度学习·yolo·计算机视觉·目标跟踪
蹦蹦跳跳真可爱58915 小时前
Python----目标检测(YOLO简介)
人工智能·python·yolo·目标检测·计算机视觉·目标跟踪
En^_^Joy16 小时前
PyQt常用控件的使用:QFileDialog、QMessageBox、QTreeWidget、QRadioButton等
开发语言·python·pyqt
蹦蹦跳跳真可爱58916 小时前
Python----目标检测(《YOLOv3:AnIncrementalImprovement》和YOLO-V3的原理与网络结构)
人工智能·python·深度学习·神经网络·yolo·目标检测·目标跟踪
Coovally AI模型快速验证17 小时前
AI+无人机如何守护濒危物种?YOLOv8实现95%精准识别
人工智能·神经网络·yolo·目标检测·无人机·cocos2d
FrankHuang8881 天前
使用高斯朴素贝叶斯算法对鸢尾花数据集进行分类
算法·机器学习·ai·分类
Mrs.Gril1 天前
RKNN3588上部署 RTDETRV2
深度学习·yolo·rknn·rtdetr
zhlei_123451 天前
封闭内网安装配置VSCode Anconda3 并配置 PyQt5开发
ide·vscode·pyqt