UNPKG

node-red-node-rdk-tools

Version:

配合RDK硬件及TROS使用的Node-RED功能包(Node-RED nodes for using TROS on a RDK hardware and TROS)

333 lines (331 loc) 11 kB
[ { "id": "edgesam_tab", "type": "tab", "label": "EdgeSAM 分割一切", "disabled": false, "info": "# EdgeSAM 分割一切\n\n## 功能介绍\n\nEdgeSAM分割算法,支持USB视频流和MIPI视频流两种模式。EdgeSAM依赖检测框输入进行分割,无需指定目标的类别信息,仅需提供框。\n\n## 使用流程\n\n### 模式1:USB视频流分割(实时)\n1. **启动视频流**:点击\"🎥 USB摄像头视频流\"按钮\n2. **查看可视化**:点击\"打开可视化页面\"在浏览器中查看实时分割结果\n3. **停止服务**:完成后点击\"停止所有服务\"\n\n### 模式2:MIPI视频流分割(实时)\n1. **启动视频流**:点击\"📹 MIPI摄像头视频流\"按钮\n2. **查看可视化**:点击\"打开可视化页面\"在浏览器中查看实时分割结果\n3. **停止服务**:完成后点击\"停止所有服务\"\n\n## 支持平台\n\n- RDK X5\n- RDK S100\n\n## 算法信息\n\n| 模型 | 平台 | 输入尺寸 | 推理帧率(fps) |\n|------|------|---------|-------------|\n| edgesam | X5 | 1×3×512×512 | 9.09 |\n| edgesam | S100 | 1×3×512×512 | 77.0 |\n\n## 核心通信配置\n\n### WebSocket视频流\n- **视频流地址**: `http://{host}:8000`\n- **图像Topic**: `/image` (JPEG编码的图像流)\n- **性能**: 实时检测,延迟低\n\n## 注意事项\n\n- EdgeSAM依赖检测框输入,本示例使用固定框(图片中央)进行分割\n- 视频流模式需要先启动视频流,再打开可视化页面\n- 分割过程需要几秒钟时间,请耐心等待", "env": [] }, { "id": "comment_video_section", "type": "comment", "z": "edgesam_tab", "name": "🎥 USB视频流分割流程", "info": "启动USB摄像头实时视频流,进行连续分割", "x": 150, "y": 200, "wires": [] }, { "id": "inject_usb_video", "type": "inject", "z": "edgesam_tab", "name": "🎥 USB摄像头视频流", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "usb_video", "payload": "start", "payloadType": "str", "x": 140, "y": 260, "wires": [ [ "exec_usb_video" ] ] }, { "id": "exec_usb_video", "type": "exec", "z": "edgesam_tab", "name": "USB视频流启动器", "command": "cd /tmp && mkdir -p logs && chmod 777 logs && source /opt/tros/humble/setup.bash && echo '=== 自动识别USB摄像头设备 ===' && DEVICE='' && for vdev in /dev/video{0..15}; do if [ -e \"$vdev\" ] && [ -c \"$vdev\" ]; then USB_PATH=$(udevadm info \"$vdev\" 2>&1 | grep 'ID_PATH=' | head -1 | cut -d'=' -f2) && if [ -n \"$USB_PATH\" ] && echo \"$USB_PATH\" | grep -qi usb; then if v4l2-ctl --device=\"$vdev\" --info >/dev/null 2>&1; then DEVICE=\"$vdev\" && echo \"✓ 找到USB摄像头: $DEVICE\" && v4l2-ctl --device=\"$DEVICE\" --info 2>&1 | grep -E 'Driver name|Card type' | head -2 && break; fi; fi; fi; done && if [ -z \"$DEVICE\" ]; then echo '⚠️ 未通过USB路径找到设备,尝试通过by-path...' && if [ -d /dev/v4l/by-path ]; then for link in /dev/v4l/by-path/*usb*-video-index0; do if [ -L \"$link\" ]; then DEVICE=$(readlink -f \"$link\") && if v4l2-ctl --device=\"$DEVICE\" --info >/dev/null 2>&1; then echo \"✓ 通过by-path找到: $DEVICE\" && break; fi; fi; done; fi; fi && if [ -z \"$DEVICE\" ]; then echo '❌ 未找到可用的USB摄像头设备' && echo '请检查USB摄像头是否已连接' && exit 1; fi && echo \"使用设备: $DEVICE\" && ls -l \"$DEVICE\" 2>&1 && echo '=== 启动EdgeSAM USB视频流(包含WebSocket服务) ===' && export CAM_TYPE=usb && ros2 launch mono_edgesam sam.launch.py device:=\"$DEVICE\" 2>&1 || (ERR_CODE=$? && echo \"启动失败,错误代码: $ERR_CODE\" && exit $ERR_CODE)", "addpay": false, "append": "", "useSpawn": true, "timer": "0", "oldrc": false, "x": 380, "y": 260, "wires": [ [ "debug_usb_video_output" ], [ "debug_usb_video_error" ], [] ] }, { "id": "debug_usb_video_output", "type": "debug", "z": "edgesam_tab", "name": "USB视频流输出", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "payload", "targetType": "msg", "statusVal": "payload", "statusType": "auto", "x": 650, "y": 240, "wires": [] }, { "id": "debug_usb_video_error", "type": "debug", "z": "edgesam_tab", "name": "USB视频流错误", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 650, "y": 280, "wires": [] }, { "id": "comment_mipi_video_section", "type": "comment", "z": "edgesam_tab", "name": "📹 MIPI视频流分割流程", "info": "启动MIPI摄像头实时视频流,进行连续分割", "x": 150, "y": 320, "wires": [] }, { "id": "inject_mipi_video", "type": "inject", "z": "edgesam_tab", "name": "📹 MIPI摄像头视频流", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "mipi_video", "payload": "start", "payloadType": "str", "x": 140, "y": 380, "wires": [ [ "exec_mipi_video" ] ] }, { "id": "exec_mipi_video", "type": "exec", "z": "edgesam_tab", "name": "MIPI视频流启动器", "command": "cd /tmp && mkdir -p logs && chmod 777 logs && source /opt/tros/humble/setup.bash && export CAM_TYPE=mipi && ros2 launch mono_edgesam sam.launch.py", "addpay": false, "append": "", "useSpawn": true, "timer": "120", "oldrc": false, "x": 380, "y": 380, "wires": [ [ "debug_mipi_video_output" ], [ "debug_mipi_video_error" ], [] ] }, { "id": "debug_mipi_video_output", "type": "debug", "z": "edgesam_tab", "name": "MIPI视频流输出", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "payload", "targetType": "msg", "statusVal": "payload", "statusType": "auto", "x": 650, "y": 360, "wires": [] }, { "id": "debug_mipi_video_error", "type": "debug", "z": "edgesam_tab", "name": "MIPI视频流错误", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 650, "y": 400, "wires": [] }, { "id": "comment_browser_section", "type": "comment", "z": "edgesam_tab", "name": "2️⃣ 查看检测结果", "info": "在浏览器中查看实时检测画面", "x": 200, "y": 440, "wires": [] }, { "id": "inject_browser", "type": "inject", "z": "edgesam_tab", "name": "打开可视化页面", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "http://{host}:8000", "payloadType": "str", "x": 140, "y": 480, "wires": [ [ "openurl_browser" ] ] }, { "id": "openurl_browser", "type": "rdk-tools openurl", "z": "edgesam_tab", "name": "", "x": 380, "y": 480, "wires": [] }, { "id": "comment_control_section", "type": "comment", "z": "edgesam_tab", "name": "🎮 控制功能", "info": "停止分割服务", "x": 150, "y": 680, "wires": [] }, { "id": "inject_stop", "type": "inject", "z": "edgesam_tab", "name": "停止分割服务", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "topic": "", "payload": "stop", "payloadType": "str", "x": 140, "y": 740, "wires": [ [ "exec_stop_all" ] ] }, { "id": "exec_stop_all", "type": "exec", "z": "edgesam_tab", "name": "停止服务", "command": "sudo pkill -9 -f hobot_usb_cam; sudo pkill -9 -f mono_edgesam; sudo pkill -9 -f hobot_codec_republish; sudo pkill -9 -f websocket; sudo pkill -9 -f python3; sudo pkill -9 -f 'ros2 launch'; sudo pkill -9 -f 'ros2 run'; sleep 2; sudo rm -rf /dev/shm/*; ros2 daemon stop 2>/dev/null; sleep 1; echo '✓ 服务已彻底停止,资源已释放'", "addpay": false, "append": "", "useSpawn": false, "timer": "10", "oldrc": false, "x": 350, "y": 740, "wires": [ [ "debug_stop_info" ], [], [] ] }, { "id": "debug_stop_info", "type": "debug", "z": "edgesam_tab", "name": "停止状态", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "payload", "targetType": "msg", "statusVal": "payload", "statusType": "auto", "x": 550, "y": 740, "wires": [] }, { "id": "global_config_edgesam", "type": "global-config", "env": [], "modules": { "node-red-node-rdk-camera": "0.0.17", "node-red-contrib-image-tools": "2.1.1" } } ]