基于yolov5的垃圾识别分类项目

 

import tkinter as tk
from tkinter import ttk
import cv2
from PIL import Image, ImageTk
from threading import Thread
import argparse
import os
import shutil
import time
from pathlib import Path
import torch
import torch.backends.cudnn as cudnn
import serial
from numpy import random
from models.experimental import attempt_load
from utils.datasets import LoadStreams, LoadImages
from utils.general import (
    check_img_size, non_max_suppression, apply_classifier, scale_coords,
    xyxy2xywh, plot_one_box, strip_optimizer, set_logging)
from utils.torch_utils import select_device, load_classifier, time_synchronized
# 定义全局变量
video_path = "ljlj.mp4"
class Detect_UI(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title("垃圾分类识别")
        self.geometry("1280x720")
        self.label_video = tk.Label(self)
        self.label_video.place(x=20, y=20, width=640, height=320)
        self.label_recognition = tk.Label(self)
        self.label_recognition.place(x=20, y=320, width=640, height=400)
        self.Counts = tk.Label(self, text="投放顺序", font=("Helvetica", 24), wraplength=140, justify="left")
        self.Counts.place(x=690, y=140, width=140, height=48)
        
        self.counts = tk.Label(self, text="", font=("Helvetica", 24), wraplength=80, justify="left")
        self.counts.place(x=740, y=280, width=48, height=48)
        
        self.amount = tk.Label(self, text="数量", font=("Helvetica", 24), wraplength=80, justify="left")
        self.amount.place(x=1060, y=140, width=96, height=48)
        
        self.Kind = tk.Label(self, text="垃圾名称", font=("Helvetica", 24), wraplength=160, justify="left")
        self.Kind.place(x=880, y=140, width=140, height=48)
        
        self.kind = tk.Label(self, text="", font=("Helvetica", 24), wraplength=400, justify="left")
        self.kind.place(x=850, y=280, width=300, height=48)
        
        
        self.ok = tk.Label(self, text="任务完成提示", font=("Helvetica", 24), wraplength=240, justify="left")
        self.ok.place(x=680, y=420, width=240, height=48)
        
        self.okok = tk.Label(self, text="", font=("Helvetica", 24), wraplength=100, justify="left")
        self.okok.place(x=750, y=500, width=100, height=48)
        
        self.fulldetect = tk.Label(self, text="满载情况", font=("Helvetica", 24), wraplength=160, justify="left")
        self.fulldetect.place(x=1000, y=420, width=160, height=48)
        self.full = tk.Label(self, text="未满载", font=("Helvetica", 24), wraplength=240, justify="left")
        self.full.place(x=960, y=500, width=240, height=48)
        # self.start_button = tk.Button(self, text="重置", command=self.refresh,width=10, height=2,bg="black",fg="white")
        # self.start_button.place(x=900, y=50)
        
        self.start_button = tk.Button(self, text="重置", command=self.refresh, width=10, height=2, bg="black", fg="white", font=("Helvetica", 20))
        self.start_button.place(x=860, y=30)
        self.video_thread = None
        self.recognition_thread = None
        self.play_video()
        self.start_recognition()

    def play_video(self):
        def play():
            cap = cv2.VideoCapture(video_path)
            while cap.isOpened():
                ret, frame = cap.rea
  • 7
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值