# ToF 点云

此示例从与 RGB 摄像头对齐的 ToF 深度构建彩色
[点云](/software-v3/depthai/depthai-components/host_nodes/pointcloud.md)，并将其流式传输到 `http://localhost:8082`
上的 DepthAI 可视化工具。有关运行时滤波器调整和附加点云工作流程，请参阅 [ToF 点云 + 运行时调整
(oak-examples)](https://github.com/luxonis/oak-examples/tree/main/depth-measurement/measurement-3d/tof-pointcloud)。

此示例需要 DepthAI v3 API，请参阅 [安装说明](/software-v3/depthai.md)。

## 源代码

#### Python

```python
#!/usr/bin/env python3
"""ToF colorized point cloud streamed to the DepthAI Visualizer.

Open http://localhost:8082 in a browser after starting this script.
"""

import depthai as dai

FPS = 30.0
SIZE = (640, 400)

with dai.Pipeline() as p:
    device = p.getDefaultDevice()

    if device.getPlatform() == dai.Platform.RVC2:
        RGB_SOCKET = dai.CameraBoardSocket.CAM_C
    else:
        RGB_SOCKET = dai.CameraBoardSocket.CAM_A

    color = p.create(dai.node.Camera).build(RGB_SOCKET, sensorFps=FPS)
    colorOut = color.requestOutput(SIZE, fps=FPS, type=dai.ImgFrame.Type.RGB888i, enableUndistortion=True)

    tof = p.create(dai.node.ToF)
    tof.build(
        boardSocket=dai.CameraBoardSocket.AUTO,
        presetMode=dai.ImageFiltersPresetMode.TOF_HIGH_RANGE,
        fps=FPS
    )

    align = p.create(dai.node.ImageAlign)
    align.setRunOnHost(True)
    tof.depth.link(align.input)
    colorOut.link(align.inputAlignTo)

    pc = p.create(dai.node.PointCloud)
    pc.initialConfig.setLengthUnit(dai.LengthUnit.MILLIMETER)
    pc.setTargetCoordinateSystem(RGB_SOCKET)
    align.outputAligned.link(pc.inputDepth)
    colorOut.link(pc.inputColor)

    remote = dai.RemoteConnection()
    remote.addTopic("pcl", pc.outputPointCloud, "3d")

    p.start()
    remote.registerPipeline(p)
    print("Visualizer running at http://localhost:8082")

    while p.isRunning():
        key = remote.waitKey(1)
        if key == ord("q"):
            break
```

### 需要帮助？

请访问[讨论论坛](https://discuss.luxonis.com/)以获取技术支持或您可能有的任何其他问题。
