目录
[# 【1】使用lz4压缩(推荐,解压更快)](# 【1】使用lz4压缩(推荐,解压更快))
[# 【2】播放数据](# 【2】播放数据)
[# 【3】播放数据](# 【3】播放数据)
[#【1】 同时录制激光雷达和双目相机话题](#【1】 同时录制激光雷达和双目相机话题)
[# 【2】播放多个话题的压缩bag](# 【2】播放多个话题的压缩bag)
[# 【3】 查看bag文件内容](# 【3】 查看bag文件内容)
[# 【4】验证录制的话题](# 【4】验证录制的话题)
[1. 图像压缩(重要!)](#1. 图像压缩(重要!))
一、激光雷达点云数据
# 【1】使用lz4压缩(推荐,解压更快)
rosbag record -O lidar_data_compressed.bag --lz4 /iv_points
# 【2】播放数据
# 直接播放,rosbag会自动解压 rosbag play lidar_data_compressed.bag # 如果需要实时播放 rosbag play -r 1.0 lidar_data_compressed.bag # 播放特定话题 rosbag play lidar_data_compressed.bag --topics /iv_points
# 循环播放3次 rosbag play -l 3 lidar_data_compressed.bag
# 从第10秒开始播放 rosbag play -s 10 lidar_data_compressed.bag
# 时间同步播放 - 发布时钟话题(适用于需要时间同步的节点) rosbag play --clock lidar_data_compressed.bag # 设置时钟频率 rosbag play --clock --hz=100 lidar_data_compressed.bag# 【3】播放数据
# 查看bag文件信息(会显示压缩格式) rosbag info lidar_data_compressed.bag
二、激光雷达点云和相机数据
#【1】 同时录制激光雷达和双目相机话题
rosbag record -O all_data_compressed.bag --lz4 /iv_points /imag1 /imag2
# 【2】播放多个话题的压缩bag
直接播放
rosbag play all_data_compressed.bag
播放特定话题
rosbag play all_data_compressed.bag --topics /iv_points /imag1
以时钟同步方式播放
rosbag play --clock all_data_compressed.bag
# 【3】 查看bag文件内容
查看bag文件信息
rosbag info all_data_compressed.bag
查看bag中的话题列表
rosbag info all_data_compressed.bag | grep "topics:"
查看具体统计信息
rosbag info all_data_compressed.bag --yaml
# 【4】验证录制的话题
查看所有话题
rostopic list
查看特定话题的信息
rostopic info /imag1
rostopic info /imag2
查看话题频率
rostopic hz /imag1
rostopic hz /imag2
三、优化建议
1. 图像压缩(重要!)
图像数据通常很大,可以考虑在节点层面压缩:
如果相机节点支持压缩,可以启用压缩话题
通常压缩后的话题名会有变化,如:
/imag1 → /imag1/compressed
【1】录制压缩后的话题:
rosbag record -O compressed_data.bag --lz4 \
/iv_points \
/imag1/compressed \
/imag2/compressed
#【2】对于学术研究(需要高质量):
使用PNG无损压缩 + BZ2
rosbag record -O research_data.bag --bz2 \
/iv_points \
/imag1/compressed \
_compressed.format:=png# 使用PNG无损压缩 + BZ2
rosbag record -O research_data.bag --bz2 \
/iv_points \
/imag1/compressed \
_compressed.format:=png
#【3】对于工程应用(需要高效率):
使用JPEG有损压缩 + LZ4
rosbag record -O engineering_data.bag --lz4 \
/iv_points \
/imag1/compressed \
_compressed.jpeg_quality:=85 \
_framerate:=10
#【4】 对于长期存储(需要最小空间):
使用低质量JPEG + BZ2
rosbag record -O archive_data.bag --bz2 \
/iv_points \
/imag1/compressed \
_compressed.jpeg_quality:=60 \
_framerate:=5
- 数据播放
最基本的方式 - 直接播放
rosbag play compressed_data.bag
带时钟同步播放(推荐)
rosbag play --clock compressed_data.bag
控制播放速度
rosbag play -r 1.0 compressed_data.bag # 正常速度
rosbag play -r 2.0 compressed_data.bag # 2倍速
rosbag play -r 0.5 compressed_data.bag # 0.5倍速