使用sunrise_camera软件测试新的模型问题

:bullseye: YOLO+ 摄像头实物判断实现方案

恭喜模型验证完成!实物判断有 3 种主流实现路径,按推荐顺序:


:pushpin: 方案一:Model Zoo 官方示例(推荐新手)

参考帖子:

快速开始

# 1. 克隆 Model Zoo
cd ~
git clone -b rdk_x5 https://github.com/D-Robotics/rdk_model_zoo.git
cd rdk_model_zoo/samples/vision/ultralytics_yolo

# 2. 运行 USB 摄像头检测
python3 demo_usb_camera.py \
  --model_path /path/to/yolov10.bin \
  --device_id 0 \
  --conf_threshold 0.5

添加实物判断逻辑

# 在 demo_usb_camera.py 的检测回调中添加
TARGET_OBJECTS = ["cup", "bottle", "phone"]  # 你要检测的实物类别

def judge_object(detections):
    """实物判断逻辑"""
    for det in detections:
        if det['class_name'] in TARGET_OBJECTS and det['confidence'] > 0.6:
            print(f"✅ 检测到目标:{det['class_name']}, 置信度:{det['confidence']:.2f}")
            # 触发动作:控制 GPIO/发送信号/记录日志
            return True
    return False

# 主循环中调用
if judge_object(results):
    # 执行后续动作
    pass

:pushpin: 方案二:ROS2 节点集成(适合机器人系统)

参考帖子:RDKx5 上部署 yolov10 和 tros 部署

步骤 1:启动检测节点

source /opt/tros/humble/setup.bash

# 启动摄像头 + YOLO 检测
ros2 launch rdk_model_zoo yolov10_detection.launch.py \
  model_path:=/path/to/yolov10.bin

步骤 2:编写判断节点

# object_judge_node.py
import rclpy
from rclpy.node import Node
from vision_msgs.msg import Detection2DArray

class ObjectJudgeNode(Node):
    def __init__(self):
        super().__init__('object_judge_node')
        self.subscription = self.create_subscription(
            Detection2DArray,
            '/detection_results',
            self.detection_callback,
            10
        )
    
    def detection_callback(self, msg):
        for detection in msg.detections:
            class_id = detection.results[0].hypothesis.class_id
            confidence = detection.results[0].hypothesis.score
            
            if class_id == 'your_target' and confidence > 0.6:
                self.get_logger().info(f'✅ 检测到目标实物!')
                self.take_action()
    
    def take_action(self):
        # 执行动作:控制机械臂/发送指令等
        pass

if __name__ == '__main__':
    rclpy.init()
    rclpy.spin(ObjectJudgeNode())

:pushpin: 方案三:Sunrise Camera Web 界面(快速验证)

你已经在用 Sunrise Camera,可以直接:

步骤 1:查看检测日志

# SSH 登录 X5
ssh root@<X5_IP>

# 实时查看检测结果
tail -f /userdata/sunrise_camera/log/sunrise.log

步骤 2:编写外部判断脚本

# judge.py - 监听日志进行实物判断
import subprocess
import re

def parse_log():
    process = subprocess.Popen(
        ['tail', '-f', '/userdata/sunrise_camera/log/sunrise.log'],
        stdout=subprocess.PIPE,
        text=True
    )
    
    for line in process.stdout:
        # 解析检测结果
        match = re.search(r'detection: (\w+), conf: ([0-9.]+)', line)
        if match:
            obj_class = match.group(1)
            confidence = float(match.group(2))
            
            if obj_class == 'your_target' and confidence > 0.6:
                print(f"✅ 发现目标实物!")
                # 触发动作

if __name__ == '__main__':
    parse_log()

核心参考资料

资源 链接 说明
Model Zoo 官方仓库 GitHub 完整示例代码
USB 摄像头 3 分钟跑通 帖子 保姆级教程
YOLOv11 性能优化 帖子 7 FPS→47 FPS 实战
目标检测 3 条路径 帖子 预装 demo/ROS2/自训模型

:warning: 关键注意事项

检查项 建议
摄像头 USB 摄像头即插即用(罗技 C270/C920)
输入尺寸 确保与量化时一致(640x640 或 672x672)
置信度阈值 初始 0.5,根据实际效果调整 0.3-0.7
帧率优化 如果帧率低,用 hrt_model_exec perf 测试模型性能

:bullseye: 下一步

告诉我你的具体场景,我可以给出更针对性的代码:

  • 要检测什么实物?(杯子、手机、特定物体?)
  • 检测到后需要做什么动作?(机械臂抓取、报警、记录?)
  • 使用什么摄像头?(USB 还是 MIPI?)
  • 需要集成到 ROS2 系统吗?

需要我帮你写完整的判断逻辑代码吗?:rocket: