小车AI视觉交互--7. 自动驾驶地图沙盘Mini版

一、运行前必做

1.关闭开机大程序,如何关闭可以参考【小车基础课程】里的“00.开发前的准备

2.调节四路巡线模块,如何调节可以参考【小车基础教程】‘’07.四路巡线模块状态打印‘’

3.因摄像头受环境光线影响较大,确保环境光线充足,且环境光线均匀。环境光线昏暗将会影响路标识别。

4.启动前将jupyter leb内核环境切换为yolo环境

image-20240829170036713

路标摆放说明

路标指示功能说明

1号车库 2号车库 鸣笛 限速

8

取消限速 左转 右转 红绿灯

路标功能解释:

1号车库:小车倒车进1号车库

2号车库:小车倒车进2号车库

鸣笛:小车蜂鸣器响一声

限速:小车减速行驶

取消限速:小车加速行驶

左转:小车执行左转命令

右转:小车执行右转命令

红绿灯:红灯亮小车停止,红灯灭小车前进

二、实验源码 

import cv2,time
import torch
from numpy import random
import queue

from models.experimental import attempt_load
from utils.datasets import LoadStreams
from utils.general import check_img_size, non_max_suppression, scale_coords, set_logging, clean_str
from utils.plots import plot_one_box
from utils.torch_utils import select_device, time_synchronized

import sys
sys.path.append('/home/pi/project_demo/lib')
from McLumk_Wheel_Sports import *

#复位舵机 Reset the servo
bot.Ctrl_Servo(1, 90)
bot.Ctrl_Servo(2, 25)

#bgr8转jpeg格式 bgr8 to jpeg format
import enum


def bgr8_to_jpeg(value, quality=75):
    return bytes(cv2.imencode('.jpg', value)[1])

#显示摄像头组件 Display camera components
import traitlets
import ipywidgets.widgets as widgets
from IPython.display import display
import time
# 线程功能操作库 Thread function operation library
import threading
import inspect
import ctypes

global classes
classes=classestemp=None
flag=rightrunflag=leftrunflag=1
leftflag=rightflag=pack1flag=pack2flag=stopflag=classflag=0
speed=5 # 速度不宜过快 The speed should not be too fast
image_widget = widgets.Image(format='jpeg', width=640, height=480)

def _async_raise(tid, exctype):
    """raises the exception, performs cleanup if needed"""
    tid = ctypes.c_long(tid)
    if not inspect.isclass(exctype):
        exctype = type(exctype)
    res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
    if res == 0:
        raise ValueError("invalid thread id")
    elif res != 1:
        # """if it returns a number greater than one, you're in trouble,
        # and you should call it again with exc=NULL to revert the effect"""
        ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None)
        
def stop_thread(thread):
    _async_raise(thread.ident, SystemExit)

def detect(weights='weights/best.pt', source='0', img_size=320, conf_thres=0.70, iou_thres=0.35, device=''):
    #Default: best.pt yolov5 model
    #best1.pt yolov5lite model
    global classes
    # Initialize
    set_logging()
    device = select_device(device)
    half = device.type != 'cpu'  # half precision only supported on CUDA

    # Load model
    model = attempt_load(weights, map_location=device)  # load FP32 model
    stride = int(model.stride.max())  # model stride
    imgsz = check_img_size(img_size, s=stride)  # check img_size
    if half:
        model.half()  # to FP16

    # Set Dataloader
    dataset = LoadStreams(source, img_size=imgsz, stride=stride)

    # Get names and colors
    names = model.module.names if h
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值