# ToF PointCloud

This example builds a colorized
[PointCloud](https://docs.luxonis.com/software-v3/depthai/depthai-components/host_nodes/pointcloud.md) from ToF depth aligned to
an RGB camera, and streams it to the DepthAI Visualizer at `http://localhost:8082`.For runtime filter tuning and additional
pointcloud workflows, see [ToF pointcloud + runtime tuning
(oak-examples)](https://github.com/luxonis/oak-examples/tree/bbc446232ad9378e03e9cb89b04dbb9f99f2448f/depth-measurement/3d-measurement/tof-pointcloud).

This example requires the DepthAI v3 API, see [installation instructions](https://docs.luxonis.com/software-v3/depthai.md).

## Source code

#### 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 = 10.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 depth into colour frame so both inputs to PointCloud share the same dimensions
    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
```

### Need assistance?

Head over to [Discussion Forum](https://discuss.luxonis.com/) for technical support or any other questions you might have.
