# 同步

同步节点用于根据时间戳同步多个输入流。它会输出一个包含来自各输入流的同步帧的分组消息。 输出消息是一个
[MessageGroup](https://docs.luxonis.com/software/depthai-components/messages/message_group.md)，包含所有输入流的同步消息。这些消息可以使用
[MessageDemux](https://docs.luxonis.com/software/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>();
```

## 输入和输出

## 消息同步

同步节点根据时间戳对齐传入的消息。同步条件和行为可以通过 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);
// ...
```

## 功能示例

 * [深度与视频同步](https://docs.luxonis.com/software/depthai/examples/depth_video_sync.md)
 * [多脚本同步](https://docs.luxonis.com/software/depthai/examples/scripts_sync.md)
 * [IMU与视频同步](https://docs.luxonis.com/software/depthai/examples/imu_video_sync.md)
 * [解复用同步脚本输出](https://docs.luxonis.com/software/depthai-components/messages/image_manip_config.md)

## 参考

### depthai.node.Sync(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

#### getSyncAttempts(self) -> int: int

Kind: Method

Gets the number of sync attempts

#### getSyncThreshold(self) -> datetime.timedelta: datetime.timedelta

Kind: Method

Gets the maximal interval between messages in the group in milliseconds

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

Kind: Method

Set on which processor the node should run

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

#### setSyncAttempts(self, maxDataSize: typing.SupportsInt)

Kind: Method

Set the number of attempts to get the specified max interval between messages in
the group

Parameter ``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

#### setSyncThreshold(self, syncThreshold: datetime.timedelta)

Kind: Method

Set the maximal interval between messages in the group

Parameter ``syncThreshold``:
Maximal interval between messages in the group

#### inputs

Kind: Property

A map of inputs

#### out

Kind: Property

Output message of type MessageGroup

### 需要帮助？

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