# MessageDemux

MessageDemux（解复用器）节点用于将 [MessageGroup](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/message_group.md)
分离为单个输出。它目前用作解复用 [Sync](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/sync.md) 节点输出的方式。

## 如何放置

#### Python

```python
pipeline = dai.Pipeline()
demux = pipeline.create(dai.node.MessageDemux)
```

#### C++

```cpp
dai::Pipeline pipeline;
auto demux = pipeline.create<dai::node::MessageDemux>();
```

## 输入和输出

## 用法

MessageDemux 节点对于处理来自单一源的不同类型数据特别有用。 例如，当使用 [Sync](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/sync.md)
节点同步多个节点的输出时，Sync 节点的输出是一个
[MessageGroup](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/message_group.md)，其中包含来自所有同步节点的消息。Demux
节点可用于将这些消息分离为单独的流。

#### Python

```python
# 创建 sync 节点并设置同步阈值
sync = pipeline.create(dai.node.Sync)
sync.setSyncThresholdMs(timedelta(milliseconds=100))

# 创建 demux 节点
demux = pipeline.create(dai.node.MessageDemux)

# 同步多个节点的输出
rgb.preview.link(sync.inputs["rgb"])
stereo.depth.link(sync.inputs["depth"])
script.outputs["out"].link(sync.inputs["script"])

sync.out.link(demux.input) # Sync 输出是一个 MessageGroup，包含来自所有同步节点的消息

# 将 MessageGroup 解复用为单个消息
demux.outputs["rgb"].link(xout1.input)
demux.outputs["depth"].link(xout2.input)
demux.outputs["script"].link(xout3.input)
```

#### C++

```cpp
// 创建 sync 节点并设置同步阈值
auto sync = pipeline.create<dai::node::Sync>();
sync->setSyncThreshold(std::chrono::milliseconds(100));

// 创建 demux 节点
auto demux = pipeline.create<dai::node::MessageDemux>();

// 同步多个节点的输出
rgb.preview.link(sync->input["rgb"]);
stereo.depth.link(sync->input["depth"]);
script.outputs["out"].link(sync->input["script"]);

sync->out.link(demux->input); // Sync 输出是一个 MessageGroup，包含来自所有同步节点的消息

// 将 MessageGroup 解复用为单个消息
demux->outputs["rgb"].link(xout1.input);
demux->outputs["depth"].link(xout2.input);
demux->outputs["script"].link(xout3.input);
```

## 功能示例

 * [解复用同步后的脚本输出](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/image_manip_config.md)

## 参考

### dai::node::MessageDemux

Kind: class

#### Input input

Kind: variable

Input message of type MessageGroup

#### OutputMap outputs

Kind: variable

A map of outputs, where keys are same as in the input MessageGroup

#### void setRunOnHost(bool runOnHost)

Kind: function

Specify whether to run on host or device By default, the node will run on device.

#### bool runOnHost()

Kind: function

Check if the node is set to run on host

#### void run()

Kind: function

#### void setProcessor(ProcessorType type)

Kind: function

Specify on which processor the node should run. RVC2 only. parameters: type: Processor type - Leon CSS or Leon MSS

#### ProcessorType getProcessor()

Kind: function

Get on which processor the node should run return: Processor type - Leon CSS or Leon MSS

#### DeviceNodeCRTP()

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props, bool confMode)

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device, std::unique_ptr< Properties > props, bool confMode)

Kind: function

### 需要帮助？

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