132gs 模组双目深度问题

:bullseye: 问题根因:标定文件格式字段名称不匹配

从社区案例 [话题 34849] 和最新诊断看,StereoNet v2.4 的 custom 模式对 YAML 字段名称非常敏感,必须使用特定格式。

你的标定文件使用了 camera_matrix_1/2,但 StereoNet v2.4 要求使用 left_camera_matrix/right_camera_matrix


:white_check_mark: 最终解决方案

步骤 1:创建正确格式的标定文件

# 1. 备份原文件
cp /opt/tros/humble/lib/mipi_cam/config/SC132gs_dual_calibration.yaml \
   /opt/tros/humble/lib/mipi_cam/config/SC132gs_dual_calibration.yaml.bak

# 2. 创建符合 StereoNet v2.4 要求的标定文件
cat > /opt/tros/humble/lib/mipi_cam/config/SC132gs_dual_calibration.yaml << 'EOF'
%YAML:1.0
image_width: 1280
image_height: 1088

# 左目内参(必须使用 left_camera_matrix)
left_camera_matrix: !!opencv-matrix
   rows: 3
   cols: 3
   dt: d
   data: [528.6953213954334, 0.0, 621.6598968327049, 
          0.0, 469.7443489102585, 344.7801912987854, 
          0.0, 0.0, 1.0]

# 左目畸变系数(必须使用 left_distortion_coefficients)
left_distortion_coefficients: !!opencv-matrix
   rows: 1
   cols: 8
   dt: d
   data: [-0.19022404784416216, 0.08737900971037368, -0.00013633102684873613, 
          2.8387028454768084e-05, 0.037123187744979025, 0.1798687498557986, 
          -0.06820294642386052, 0.10684527621059339]

# 右目内参(必须使用 right_camera_matrix)
right_camera_matrix: !!opencv-matrix
   rows: 3
   cols: 3
   dt: d
   data: [529.2760196145524, 0.0, 654.6320151265384, 
          0.0, 470.4236596788936, 318.0571160826385, 
          0.0, 0.0, 1.0]

# 右目畸变系数(必须使用 right_distortion_coefficients)
right_distortion_coefficients: !!opencv-matrix
   rows: 1
   cols: 8
   dt: d
   data: [-0.08168737119014227, 0.051348177058130356, 0.00010479656330654928, 
          -8.819143676712554e-06, 0.02454473699094, 0.28711736495579887, 
          -0.06268635878956813, 0.07182651571052037]

# 旋转矩阵(必须使用 R)
R: !!opencv-matrix
   rows: 3
   cols: 3
   dt: d
   data: [0.9999771405493721, -0.0008865181729254466, -0.006703168223329922, 
          0.000844157865516232, 0.9999796745904039, -0.006319636347751682, 
          0.006708634451158759, 0.006313833352156998, 0.9999575639656925]

# 平移向量(必须使用 T)
T: !!opencv-matrix
   rows: 3
   cols: 1
   dt: d
   data: [-0.06981825961809152, -0.00031854332254735906, -3.61077528349911e-05]

# 基线距离(必须使用 baseline,单位:米)
baseline: 0.06981825961809152
EOF

步骤 2:确认 run_stereo.sh 配置

# 编辑脚本
vim /userdata/data/test/run_stereo.sh

# 确保以下配置(约 35-60 行):
use_mipi_cam=False
calib_method="custom"
stereo_calib_file_path="/opt/tros/humble/lib/mipi_cam/config/SC132gs_dual_calibration.yaml"
render_type="distance"

步骤 3:清理进程并重新运行

# 1. 清理所有残留进程
killall mipi_cam stereonet_model_node hobot_codec_republish websocket 2>/dev/null
sleep 3

# 2. 启动相机节点
bash run_cam.sh --rotation 90.0 --log_level INFO &

# 3. 等待 5 秒后启动 StereoNet
sleep 5
cd /userdata/data/test/
bash run_stereo.sh --stereonet_version v2.4 2>&1 | tee stereo_final.log

步骤 4:验证深度输出

# 新开终端检查
ros2 topic list | grep -E "depth|stereo"
ros2 topic hz /StereoNetNode/stereonet_depth

# 查看深度数据
ros2 topic echo /StereoNetNode/stereonet_depth --once

:clipboard: 关键字段名称对照表

:cross_mark: 错误字段名 :white_check_mark: 正确字段名 说明
camera_matrix_1 left_camera_matrix 左目内参
camera_matrix_2 right_camera_matrix 右目内参
distortion_1 left_distortion_coefficients 左目畸变
distortion_2 right_distortion_coefficients 右目畸变
rectification_1 (可选) 校正矩阵
projection_1 (可选) 投影矩阵
R R 旋转矩阵 :white_check_mark:
T T 平移向量 :white_check_mark:
baseline baseline 基线距离 :white_check_mark:

:magnifying_glass_tilted_left: 如果仍有问题

# 1. 查看 StereoNet 初始化日志
grep -A50 "init StereoNetNode" stereo_final.log

# 2. 检查标定文件加载
grep -i "calib\|baseline\|custom\|left_camera" stereo_final.log | tail -20

# 3. 检查崩溃原因
grep -E "ERROR|died|segmentation|invalid" stereo_final.log | tail -20

:books: 相关参考


核心修复点:将 camera_matrix_1/2 改为 left_camera_matrix/right_camera_matrix,将 distortion_1/2 改为 left_distortion_coefficients/right_distortion_coefficients

执行后把新的日志输出补充到帖子,特别是 grep -A50 "init StereoNetNode" stereo_final.log 的输出!