# RGBD

RGBD节点将同步的深度帧和彩色帧合并为单个点云和RGB-D数据流。它在内部使用一个同步子节点，将深度（来自StereoDepth节点）和彩色图像对齐，以便在主机上进行处理。

## 如何放置

#### Python

```python
import depthai as dai

with dai.Pipeline() as pipeline:
  rgbd = pipeline.create(dai.node.RGBD)
  # 将彩色和深度输出连接到RGBD输入
  color.out.link(rgbd.inColor)
  depth.out.link(rgbd.inDepth)

  # 或使用自动创建
  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>();
// 将彩色和深度输出连接到RGBD输入
color->out.link(rgbd->inColor);
depth->out.link(rgbd->inDepth);

// 或使用自动创建
rgbd = pipeline.create<node::RGBD>().build(
    autocreate=true,
    presetMode=StereoDepth::PresetMode::DEFAULT,
    std::pair<int, int> size = {640, 400}
);
```

## 输入与输出

Sync子节点在处理前将彩色帧和深度帧对齐到MessageGroup中。

## 配置

 * build() / build(autocreate, presetMode, size) - 创建节点，可选择性自动创建彩色/深度节点，选择StereoDepth::PresetMode，并指定帧大小（宽度，高度）。

 * setDepthUnit(depthUnit) - 通过StereoDepthConfig::AlgorithmControl::DepthUnit选择深度单位（例如毫米或米）进行转换。

 * useCPU() - 强制使用单线程CPU处理（默认）。

 * useCPUMT(numThreads) - 启用多线程CPU处理，指定numThreads（默认值：2）。

 * useGPU(device) - 将处理卸载到GPU（需要Kompute支持），可选择指定GPU设备索引。

 * printDevices() - 打印可用的GPU设备和功能。

## 使用

放置并连接后，启动管线并获取输出：

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

## 功能示例

 * [RGB-D点云可视化（Rerun/Open3d/OAK Visualizer）](https://docs.luxonis.com/software-v3/depthai/examples/rgbd/rgbd.md)
 * [RGB-D点云可视化（自动创建）](https://docs.luxonis.com/software-v3/depthai/examples/rgbd/rgbd_autocreate.md)

## 参考

### 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, const 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, const 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 ( Depth , 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

### 需要帮助？

请前往 [OAKChina 官网](https://www.oakchina.cn/) 获取技术支持或解答您的任何疑问。
