此页面由 AI 自动翻译。查看英文原版
最后更新

本页目录

  • 在 Script 节点中创建消息
  • 在主机上创建消息
  • 消息保存和加载函数
  • 重映射可转换消息
Claude CodeCodexCursor
Luxonis 智能体工具包为你常用的编程智能体加载 Luxonis 上下文与技能,更快地基于 OAK 开发应用。
安装工具包
最后更新
消息在链接的 节点 之间发送。节点之间通信的唯一方式是相互发送消息。在目录(页面左侧)中,所有 DepthAI 消息类型都列在 Messages 条目下。您可以点击它们以了解更多信息。

在 Script 节点中创建消息

DepthAI 消息可以在设备上由节点自动创建,也可以在 Script 节点中手动创建。在下面的示例中,代码取自 Script Camera Control 示例,其中 Camera Control 消息每秒在 Script 节点中创建并发送到 Camera 的输入 (cam.inputControl)。
Python
1script = pipeline.create(dai.node.Script)
2script.setScript("""
3  # 创建消息
4  ctrl = CameraControl(1)
5  # 配置消息
6  ctrl.setCaptureStill(True)
7  # 从 Script 节点发送消息
8  node.io['out'].send(ctrl)
9""")

在主机上创建消息

它也可以在主机计算机上创建,并通过 输入队列 发送到设备。在下面的示例中,我们删除了所有与展示如何在主机上创建消息并发送到设备无关的代码。
Python
1imgFrame = dai.ImgFrame()
2frame = np.ones((300, 300, 3), np.uint8) * 255
3imgFrame.setData(frame)
4imgFrame.setWidth(frame.shape[1])
5imgFrame.setHeight(frame.shape[0])
6imgFrame.setType(dai.ImgFrame.Type.BGR888i)
7
8with dai.Pipeline() as pipeline:
9    # 定义源和输出
10    script = pipeline.create(dai.node.Script)
11    cam_input_q = script.inputs["frame"].createInputQueue()
12    script.setScript("""
13    import time
14    while True:
15        frame = node.io["frame"].get()
16        if frame:
17          node.warn("Received frame")
18        time.sleep(0.1)
19    """)
20
21    pipeline.start()
22    while pipeline.isRunning():
23
24        cam_input_q.send(imgFrame)
25        time.sleep(1)

消息保存和加载函数

使用 save() 将 DepthAI 消息写入文件,并使用 load() 将其读回:
Python
1msg.save("name.dai")
2msg.load("name.dai")
保存的文件是一个二进制 protobuf 封装。以下消息类型支持这些函数:

重映射可转换消息

图像派生消息可以携带一个 ImgTransformation,它记录了流在管道中如何被调整大小、裁剪、旋转、对齐或以其他方式重映射。实现 Transformable 接口的消息可以使用该数据在另一个帧的坐标系中返回一个副本:
Python
1remappedMessage = message.transformTo(targetTransformation)
实际上,targetTransformation 通常来自您想要在其上绘制或进行比较的目标 ImgFrame。DepthAI 3.7.1 在以下方面公开了此流程:对于分割输出,请注意 SegmentationMask.transformTo(...) 当前返回一个副本,而不重映射掩码像素。当您需要另一个坐标系中的掩码时,请在生成掩码之前对齐源帧。