from maix import camera, display, image, nn, app # 1. 初始化模型 (请确保模型文件 .mud 路径正确) detector = nn.YOLOv5(model="/root/model_279350.mud", dual_buff=True) # 2. 初始化摄像头,分辨率与模型输入匹配 cam = camera.Camera(detector.input_width(), detector.input_height(), detector.input_format()) disp = display.Display() # 3. 主循环:实时检测与显示 while not app.need_exit(): img = cam.read() # 从摄像头读取一帧 objs = detector.detect(img, conf_th=0.5, iou_th=0.45) # 执行YOLO11推理 for obj in objs: # 绘制所有检测到的目标 img.draw_rect(obj.x, obj.y, obj.w, obj.h, color=image.COLOR_RED) msg = f'{detector.labels[obj.class_id]}: {obj.score:.2f}' img.draw_string(obj.x, obj.y, msg, color=image.COLOR_RED) disp.show(img) # 更新屏幕显示