# 同步（Sync）

Sync 节点用于基于时间戳同步多个输入流。它输出一个分组消息，其中包含来自输入流的同步帧。 输出消息是一个
[MessageGroup](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/message_group.md)，包含来自所有输入流的同步消息。可以使用
[MessageDemux](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/message_demux.md) 节点进行解复用。

## 如何放置

#### Python

```python
pipeline = dai.Pipeline()
sync = pipeline.create(dai.node.Sync)
```

#### C++

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

## 输入与输出

## 消息同步

Sync 节点根据时间戳对齐传入的消息。同步标准和行为可以通过 depthai.node.Sync.setSyncThreshold 和 depthai.node.Sync.setSyncAttempts 方法进行配置。更多信息请参见
[参考部分](#Reference)。

### 同步逻辑

## 使用示例

#### Python

```python
pipeline = dai.Pipeline()
sync = pipeline.create(dai.node.Sync)

# 配置时间戳对齐的阈值
sync.setSyncThreshold(timedelta(milliseconds=50))

# 配置需要同步的输入
camRgb.video.link(sync.inputs["input1"])
stereo.depth.link(sync.inputs["input2"])

sync.out.link(xout.input)
# ...
```

#### C++

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

// 配置时间戳对齐的阈值
sync->setSyncThreshold(std::chrono::milliseconds(50));

// 配置需要同步的输入
camRgb.video.link(sync->input["input1"]);
stereo.depth.link(sync->input["input2"]);

sync->out.link(xout.input);
// ...
```

## 功能示例

 * [Sync](https://docs.luxonis.com/software-v3/depthai/examples/sync/sync.md) - 同步两个或多个数据流。
 * [解复用同步的脚本输出](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/image_manip_config.md) - 使用 Sync 节点同步来自
   Script 节点的多个输出，然后使用 MessageDemux 进行解复用。

## 参考

### dai::node::Sync

Kind: class

Sync node. Performs syncing between image frames.

#### SyncProperties::TimestampSource TimestampSource

Kind: enum

#### InputMap inputs

Kind: variable

A map of inputs

#### Output out

Kind: variable

Output message of type MessageGroup

#### void setSyncThreshold(std::chrono::nanoseconds syncThreshold)

Kind: function

Set the maximal interval between messages in the group parameters: syncThreshold: Maximal interval between messages in the group

#### void setSyncAttempts(int syncAttempts)

Kind: function

Set the number of attempts to get the specified max interval between messages in the group parameters: syncAttempts: Number of
attempts to get the specified max interval between messages in the group: if syncAttempts = 0 then the node sends a message as
soon at the group is filled; if syncAttempts > 0 then the node will make syncAttemts attempts to synchronize before sending out a
message; if syncAttempts = -1 (default) then the node will only send a message if successfully synchronized

#### 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

#### void setTimestampSource(TimestampSource source)

Kind: function

Specify the timestamp source

#### TimestampSource getTimestampSource()

Kind: function

Get the timestamp source

#### std::chrono::nanoseconds getSyncThreshold()

Kind: function

Gets the maximal interval between messages in the group in milliseconds

#### int getSyncAttempts()

Kind: function

Gets the number of sync attempts

#### 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

#### 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/) 获取技术支持或解答您的任何疑问。
