# RGBD

The RGBD node combines synchronized depth and color frames into a single point cloud and RGB-D data stream. It internally uses a
Sync subnode to align depth (from a StereoDepth node) and color images for processing on the host.

## How to place it

#### Python

```python
import depthai as dai

with dai.Pipeline() as pipeline:
  rgbd = pipeline.create(dai.node.RGBD)
  # Link color and depth outputs to RGBD inputs
  color.out.link(rgbd.inColor)
  depth.out.link(rgbd.inDepth)

  # Or use autocreate
  rgbd = pipeline.create(dai.node.RGBD).build(
      autocreate=True,
      presetMode=dai.StereoDepth.PresetMode.DEFAULT,
      size=(640, 400)
  )
  pipeline.start()
```

#### C++

```cpp
#include <depthai/pipeline/Pipeline.hpp>
#include <depthai/pipeline/node/host/RGBD.hpp>

using namespace dai;

Pipeline pipeline;
auto rgbd = pipeline.create<node::RGBD>();
// Link color and depth outputs to RGBD inputs
color->out.link(rgbd->inColor);
depth->out.link(rgbd->inDepth);

// Or use autocreate
rgbd = pipeline.create<node::RGBD>().build(
    autocreate=true,
    presetMode=StereoDepth::PresetMode::DEFAULT,
    std::pair<int, int> size = {640, 400}
);
```

## Inputs and Outputs

The Sync subnode aligns color and depth frames into a MessageGroup before processing.

## Configuration

 * build() / build(autocreate, presetMode, size) - Create the node, optionally autocreating color/depth nodes, selecting a
   StereoDepth::PresetMode, and specifying frame size as (width, height).

 * setDepthUnit(depthUnit) - Choose the depth unit for conversion (e.g., millimeters or meters) via
   StereoDepthConfig::AlgorithmControl::DepthUnit.

 * useCPU() - Force single-threaded CPU processing (default).

 * useCPUMT(numThreads) - Enable multi-threaded CPU processing, specifying numThreads (default: 2).

 * useGPU(device) - Offload processing to GPU (requires Kompute support), optionally specifying a GPU device index.

 * printDevices() - Print available GPU devices and capabilities.

## Usage

Once placed and linked, start the pipeline and fetch outputs:

```python
with dai.Pipeline() as p:
    qPcl = rgbd.pcl.createOutputQueue()
    qRgbd = rgbd.rgbd.createOutputQueue()
    pipeline.start()
    pipeline.start()
        pclData = qPcl.get()   # type: dai.PointCloudData
        rgbdData = qRgbd.get() # type: dai.RGBDData
```

## Examples of functionality

 * [RGB-D Point Cloud Visualization (Rerun/Open3d/OAK
   Visualizer)](https://docs.luxonis.com/software-v3/depthai/examples/rgbd/rgbd.md)
 * [RGB-D Point Cloud Visualization (Autocreate)](https://docs.luxonis.com/software-v3/depthai/examples/rgbd/rgbd_autocreate.md)

## Reference

### dai::node::RGBD

Kind: class

RGBD node. Combines depth and color frames into a single point cloud.

#### Subnode < node::Sync > sync

Kind: variable

#### InputMap & inputs

Kind: variable

#### std::string colorInputName

Kind: variable

#### std::string depthInputName

Kind: variable

#### Input & inColor

Kind: variable

#### Input & inDepth

Kind: variable

#### Output pcl

Kind: variable

Output point cloud.

#### Output rgbd

Kind: variable

Output RGBD frames.

#### RGBD()

Kind: function

#### ~RGBD()

Kind: function

#### std::shared_ptr< RGBD > build()

Kind: function

#### std::shared_ptr< RGBD > build(bool autocreate, StereoDepth::PresetMode mode, std::pair< int, int > frameSize, std::optional<
float > fps)

Kind: function

Build RGBD node with specified size. Note that this API is global and if used autocreated cameras can't be reused.

parameters: autocreate: If true, will create color and depth nodes if they don't exist.; frameSize: Size of the frames

#### std::shared_ptr< RGBD > build(const std::shared_ptr< Camera > & camera, const DepthSource & depthSource, std::pair< int, int
> frameSize, std::optional< float > fps)

Kind: function

Build RGBD node with camera and depth source node.

parameters: camera: Camera node to use for color frames; depthSource: Depth source node ( StereoDepth , NeuralDepth , or ToF );
frameSize: Size of the frames; fps: FPS of the frames

#### void setDepthUnit(StereoDepthConfig::AlgorithmControl::DepthUnit depthUnit)

Kind: function

#### void useCPU()

Kind: function

Use single-threaded CPU for processing.

#### void useCPUMT(uint32_t numThreads)

Kind: function

Use multi-threaded CPU for processing.

parameters: numThreads: Number of threads to use

#### void useGPU(uint32_t device)

Kind: function

Use GPU for processing (needs to be compiled with Kompute support)

parameters: device: GPU device index

#### void printDevices()

Kind: function

Print available GPU devices.

#### void buildInternal()

Kind: function

### Need assistance?

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