# MessageDemux

MessageDemux（解复用）节点用于将 [MessageGroup](https://docs.luxonis.com/software/depthai-components/messages/message_group.md)
分离为独立的输出。它主要用于对 [Sync](https://docs.luxonis.com/software/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/depthai-components/nodes/sync.md)
节点同步多个节点的输出时，Sync 节点的输出是一个包含所有同步节点消息的
[MessageGroup](https://docs.luxonis.com/software/depthai-components/messages/message_group.md)。Demux 节点可用于将消息分离为独立的流。

#### Python

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

# 创建解复用节点
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
// 创建同步节点并设置同步阈值
auto sync = pipeline.create<dai::node::Sync>();
sync->setSyncThreshold(std::chrono::milliseconds(100));

// 创建解复用节点
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/depthai-components/messages/image_manip_config.md)

## 参考

### depthai.node.MessageDemux(depthai.Node)

Kind: Class

#### getProcessor(self) -> depthai.ProcessorType: depthai.ProcessorType

Kind: Method

Get on which processor the node should run

Returns:
Processor type - Leon CSS or Leon MSS

#### setProcessor(self, arg0: depthai.ProcessorType)

Kind: Method

Set on which processor the node should run

Parameter ``type``:
Processor type - Leon CSS or Leon MSS

#### input

Kind: Property

Input message of type MessageGroup

#### outputs

Kind: Property

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

### 需要帮助？

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