自学内容网 自学内容网

使用 YOLOv5-Lite 模型对视频中的垃圾进行分类检测,并通过舵机控制对应区域,同时显示检测帧率。

import cv2
import numpy as np
import onnxruntime as ort
import time
import torch
import torchvision.transforms as transforms
from PIL import Image
import numpy as np
from torchvision import models
import json
from gpiozero import Servo
from time import sleep
import requests

myGPIO1 = 14
myGPIO2 = 15 # 第二个舵机的GPIO引脚
myCorrection = 0
maxPW = (2.0 + myCorrection) / 1000
minPW = (1.0 - myCorrection) / 1000

实例化两个舵机

servo1 = Servo(myGPIO1, min_pulse_width=minPW, max_pulse_width=maxPW)
servo2 = Servo(myGPIO2, min_pulse_width=minPW, max_pulse_width=maxPW)

启动时复位舵机到 0.0

print(“Resetting servos to initial position (0.0)”)
servo1.value = 0.0
servo2.value = 0.0
sleep(1)

positions = {
1: (-1.0, 0.0), # 区域1
2: (1.0, 0.0), # 区域2
3: (0.0, -1.0), # 区域3
4: (0.0, 1.0) # 区域4
}

def plot_one_box(x, img, color=None, label=None, line_thickness=None):
“”"
description: Plots one bounding box on image img,
this function comes from YoLov5 project.
param:
x: a box likes [x1,y1,x2,y2]
img: a ope


原文地址:https://blog.csdn.net/huanghm88/article/details/142891493

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!