intel realsense d435i自制TUM数据集
时间: 2025-07-06 13:49:09 浏览: 1
### 使用Intel RealSense D435i制作TUM格式数据集的步骤
要使用Intel RealSense D435i摄像头制作TUM格式的数据集,需要完成以下几个关键部分:录制视频文件、提取深度和RGB图像的时间戳信息,并将这些信息保存到对应的文本文件中。以下是详细的说明:
#### 1. 录制视频文件
通过Intel RealSense Viewer工具或代码接口录制包含深度流(Depth Stream)和彩色流(Color Stream)的视频文件。确保设置正确的分辨率和帧率。
- 在Intel RealSense Viewer中:
- 设置Depth Stream和Color Stream的分辨率为640×480[^5]。
- 设置采集帧率为30 fps[^5]。
- 点击左上方的“Record”按钮开始录制视频。
- 如果遇到报错,需要修改存储路径以确保录制成功[^5]。
- 或者通过Python代码录制:
```python
import pyrealsense2 as rs
import numpy as np
pipeline = rs.pipeline()
config = rs.config()
config.enable_device_from_file("/path/to/your/recording.bag") # 替换为你的bag文件路径[^1]
pipeline.start(config)
try:
while True:
frames = pipeline.wait_for_frames()
depth_frame = frames.get_depth_frame()
color_frame = frames.get_color_frame()
if not depth_frame or not color_frame:
continue
depth_image = np.asanyarray(depth_frame.get_data())
color_image = np.asanyarray(color_frame.get_data())
finally:
pipeline.stop()
```
#### 2. 提取时间戳信息
从录制的`.bag`文件中提取深度和RGB图像的时间戳信息,并将其保存到两个文本文件中(`rgb.txt`和`depth.txt`)。每个文件的每一行应包含时间戳和对应的文件名。
- 示例代码:
```python
import pyrealsense2 as rs
import os
config = rs.config()
config.enable_device_from_file("/path/to/your/recording.bag") # 替换为你的bag文件路径
pipeline = rs.pipeline()
pipeline.start(config)
save_path = '/path/to/save/dataset/' # 替换为你的保存路径[^1]
file_handle1 = open(os.path.join(save_path, 'rgb.txt'), 'w') # RGB时间戳文件[^1]
file_handle2 = open(os.path.join(save_path, 'depth.txt'), 'w') # 深度时间戳文件
frame_count = 0
try:
while True:
frames = pipeline.wait_for_frames()
timestamp = frames.get_timestamp() / 1000.0 # 转换为秒单位
color_frame = frames.get_color_frame()
depth_frame = frames.get_depth_frame()
if color_frame:
file_name = f"frame-{frame_count:06d}.color.jpg"
file_handle1.write(f"{timestamp:.6f} {file_name}\n")
image = np.asanyarray(color_frame.get_data())
cv2.imwrite(os.path.join(save_path, file_name), image)
if depth_frame:
file_name = f"frame-{frame_count:06d}.depth.png"
file_handle2.write(f"{timestamp:.6f} {file_name}\n")
image = np.asanyarray(depth_frame.get_data(), dtype=np.uint16)
cv2.imwrite(os.path.join(save_path, file_name), image)
frame_count += 1
finally:
pipeline.stop()
file_handle1.close()
file_handle2.close()
```
#### 3. 配置相机参数
为了使数据集兼容TUM格式,还需要提供相机的内参矩阵。可以通过ROS节点获取这些参数。
- 使用ROS命令获取相机参数:
```bash
roslaunch realsense2_camera rs_rgbd.launch
rostopic echo /camera/color/camera_info
```
将输出的`K`矩阵保存到`calib.txt`文件中[^4]。
#### 4. 数据集目录结构
最终的数据集目录结构应如下所示:
```
/path/to/save/dataset/
├── rgb.txt
├── depth.txt
├── calib.txt
├── frame-000000.color.jpg
├── frame-000000.depth.png
├── frame-000001.color.jpg
├── frame-000001.depth.png
...
```
---
### 注意事项
- 确保安装了必要的驱动程序和库文件,例如`libusb`规则文件[^3]。
- 如果计划在SLAM算法(如ORB-SLAM3)中使用该数据集,请验证时间戳对齐和相机参数的正确性[^3]。
---
阅读全文
相关推荐


















