d435i 点云可视化 open3d
时间: 2025-06-14 16:54:20 浏览: 22
### 使用 Open3D 实现 D435i 设备点云数据的可视化
为了实现 Intel RealSense D435i 设备的点云数据可视化,可以通过 Python 结合 Open3D 库来完成。以下是具体方法:
#### 安装依赖库
首先需要安装 `pyrealsense2` 和 `open3d` 这两个库。这两个库分别用于获取 D435i 的传感器数据以及对其进行可视化。
```bash
pip install pyrealsense2 open3d
```
#### 获取点云数据
Intel 提供了官方文档和示例代码,说明如何通过 `pyrealsense2` 来捕获 D435i 的深度图像和彩色图像,并将其转换为点云格式[^1]。以下是一个简单的代码片段,演示如何从 D435i 中提取点云数据:
```python
import pyrealsense2 as rs
import numpy as np
import open3d as o3d
# 配置管道
pipeline = rs.pipeline()
config = rs.config()
# 启动设备流
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
profile = 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
# 将帧数据转换为 NumPy 数组
depth_image = np.asanyarray(depth_frame.get_data())
color_image = np.asanyarray(color_frame.get_data())
# 创建点云对象
pc = rs.pointcloud()
points = pc.calculate(depth_frame)
# 转换为 Open3D 点云格式
vertices = np.asarray(points.get_vertices()).view(np.float32).reshape(-1, 3) # xyz
texture_coordinates = np.asarray(points.get_texture_coordinates()).view(np.float32).reshape(-1, 2) # uv
point_cloud_o3d = o3d.geometry.PointCloud()
point_cloud_o3d.points = o3d.utility.Vector3dVector(vertices)
finally:
pipeline.stop()
```
以上代码实现了从 D435i 捕捉深度数据并将其转化为 Open3D 支持的点云格式[^2]。
#### 可视化点云
一旦获得了点云数据,可以利用 Open3D 的内置函数进行实时渲染。下面是一段完整的代码示例,展示了如何动态显示来自 D435i 的点云数据:
```python
def visualize_d435i_point_cloud():
vis = o3d.visualization.Visualizer()
vis.create_window(window_name="D435i Point Cloud", width=800, height=600)
opt = vis.get_render_option()
opt.background_color = np.asarray([0, 0, 0])
opt.point_size = 2
geom_added = False
point_cloud_o3d = None
try:
while True:
frames = pipeline.wait_for_frames()
depth_frame = frames.get_depth_frame()
if not depth_frame:
continue
pc = rs.pointcloud()
points = pc.calculate(depth_frame)
vertices = np.asarray(points.get_vertices()).view(np.float32).reshape(-1, 3)
new_pcd = o3d.geometry.PointCloud()
new_pcd.points = o3d.utility.Vector3dVector(vertices)
if not geom_added:
vis.add_geometry(new_pcd)
point_cloud_o3d = new_pcd
geom_added = True
else:
point_cloud_o3d.points = new_pcd.points
vis.update_geometry(point_cloud_o3d)
vis.poll_events()
vis.update_renderer()
finally:
pipeline.stop()
if __name__ == "__main__":
visualize_d435i_point_cloud()
```
这段代码创建了一个持续更新的窗口,能够实时显示由 D435i 抓取的点云数据[^3]。
#### 快捷键操作提示
在运行上述程序时,可能会涉及一些快捷键操作以便更好地调整视角或保存截图。根据之前的描述[R 是重置视角,Q 是退出窗口](https://stackoverflow.com/questions/59740047/open3d-python-how-to-save-a-screenshot-of-the-point-cloud)[^4]。
---
###
阅读全文
相关推荐

















