解复用同步脚本输出
解复用同步脚本输出
类似示例
演示
Command Line
1~/depthai-python/examples/Sync $ python3 demux_message_group.py
2Start
3Buffer 1 timestamp: 0:00:03.581073
4Buffer 2 timestamp: 0:00:03.591084
5----------
6Buffer 1 timestamp: 0:00:04.583100
7Buffer 2 timestamp: 0:00:04.497079
8----------
9Buffer 1 timestamp: 0:00:06.587174
10Buffer 2 timestamp: 0:00:06.611154
11----------
12Buffer 1 timestamp: 0:00:07.589147
13Buffer 2 timestamp: 0:00:07.517125
14----------
15Buffer 1 timestamp: 0:00:09.593076
16Buffer 2 timestamp: 0:00:09.631089
17----------
18Buffer 1 timestamp: 0:00:10.595106
19Buffer 2 timestamp: 0:00:10.537082设置
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py源代码
Python
PythonGitHub
1import depthai as dai
2import time
3from datetime import timedelta
4
5pipeline = dai.Pipeline()
6
7script1 = pipeline.create(dai.node.Script)
8script1.setScript("""
9from time import sleep
10
11while True:
12 sleep(1)
13 b = Buffer(512)
14 b.setData(bytes(4 * [i for i in range(0, 128)]))
15 b.setTimestamp(Clock.now())
16 node.io['out'].send(b)
17""")
18
19script2 = pipeline.create(dai.node.Script)
20script2.setScript("""
21from time import sleep
22
23while True:
24 sleep(0.3)
25 b = Buffer(512)
26 b.setData(bytes(4 * [i for i in range(128, 256)]))
27 b.setTimestamp(Clock.now())
28 node.io['out'].send(b)
29""")
30
31sync = pipeline.create(dai.node.Sync)
32sync.setSyncThreshold(timedelta(milliseconds=100))
33
34demux = pipeline.create(dai.node.MessageDemux)
35
36xout1 = pipeline.create(dai.node.XLinkOut)
37xout1.setStreamName("xout1")
38xout2 = pipeline.create(dai.node.XLinkOut)
39xout2.setStreamName("xout2")
40
41script1.outputs["out"].link(sync.inputs["s1"])
42script2.outputs["out"].link(sync.inputs["s2"])
43sync.out.link(demux.input)
44demux.outputs["s1"].link(xout1.input)
45demux.outputs["s2"].link(xout2.input)
46
47with dai.Device(pipeline) as device:
48 print("Start")
49 q1 = device.getOutputQueue("xout1", maxSize=10, blocking=True)
50 q2 = device.getOutputQueue("xout2", maxSize=10, blocking=True)
51 while True:
52 bufS1 = q1.get()
53 bufS2 = q2.get()
54 print(f"Buffer 1 timestamp: {bufS1.getTimestamp()}")
55 print(f"Buffer 2 timestamp: {bufS2.getTimestamp()}")
56 print("----------")
57 time.sleep(0.2)工作原理
- 初始化一个 DepthAI 管道。
- 创建两个 Script 节点,每个脚本以不同的间隔生成并发送数据缓冲区。
- 设置一个具有同步阈值的 Sync 节点。
- 集成一个 MessageDemux 节点来分离同步的数据流。
- 将 Script 节点的输出链接到 Sync 节点,然后从 Sync 节点链接到 MessageDemux 节点。
- 启动管道并从 MessageDemux 节点持续接收解复用的数据。
- 打印解复用数据的时戳以供比较。
管道
需要帮助?
请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。