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

本页目录

  • 如何放置
  • 输入和输出
  • 用法
  • 功能示例
  • 参考
Claude CodeCodexCursor
Luxonis 智能体工具包为你常用的编程智能体加载 Luxonis 上下文与技能,更快地基于 OAK 开发应用。
安装工具包
最后更新
Supported on:RVC2RVC4
在运行时启用消息流的打开和关闭。

如何放置

Python

Python
1with dai.Pipeline() as pipeline:
2    gate  = pipeline.create(dai.node.Gate)

C++

C++
1dai::Pipeline pipeline;
2auto gate = pipeline.create<dai::node::Gate>();

输入和输出

用法

Python

Python
1with dai.Pipeline(device) as pipeline:
2    camera = pipeline.create(dai.node.Camera).build()
3    cameraOut = camera.requestOutput((640, 400), fps=30)
4
5    gate  = pipeline.create(dai.node.Gate)
6    cameraOut.link(gate.input)
7    cameraQueue = gate.output.createOutputQueue()
8    gateControlQueue = gate.inputControl.createInputQueue()
9
10    gateControl = dai.GateControl()
11
12    pipeline.start()
13
14    startTime = time.monotonic()
15    gateOpen = True
16
17    # Open gate every odd second and close every even second
18    while pipeline.isRunning():
19        currentTime = time.monotonic()
20        if (startTime-currentTime) % 2 == 0: 
21            if not gateOpen:
22                gateControlQueue.send(dai.GateControl.openGate())
23                openGate = True
24        else: 
25            if gateOpen:
26                gateControlQueue.send(dai.GateControl.closeGate())
27                gateOpen = False

C++

C++
1while(pipeline.isRunning()) {
2    auto frame = cameraQueue->tryGet<dai::ImgFrame>();
3    if(frame != nullptr) {
4        cv::imshow("camera", frame->getCvFrame());
5    }
6
7    auto currentTime = std::chrono::steady_clock::now();
8    auto elapsedSeconds = std::chrono::duration_cast<std::chrono::seconds>(currentTime - startTime).count();
9    auto oddSecond = (elapsedSeconds % 2) != 0;
10
11    if(oddSecond) {
12        if(!gateOpen) {
13            gateControlQueue->send(dai::GateControl::openGate());
14            gateOpen = true;
15        }
16    } else {
17        if(gateOpen) {
18            gateControlQueue->send(dai::GateControl.closeGate());
19            gateOpen = false;
20        }
21    }
22
23    int key = cv::waitKey(1);
24    if(key == 'q') {
25        pipeline.stop();
26        break;
27    }
28}

功能示例

参考

class

dai::node::Gate

#include Gate.hpp
variable
std::shared_ptr< GateControl > initialConfig
variable
Input input
Main data input.
  • Accepts arbitrary Buffer messages (e.g., ImgFrame, NNData). If the Gate is Open, messages received here are forwarded to 'output'. If the Gate is Closed, messages received here are discarded/dropped.
  • Default queue size: 1 Blocking: False
variable
Output output
Main data output.
  • Forwards messages that were allowed through the Gate. The data type matches the input message.
variable
Input inputControl
Control input.
  • Accepts 'GateControl' messages to dynamically change the Gate's state. Use this to Open/Close the gate or set it to pass a specific number of frames at runtime.
  • Default queue size: 4
function
Gate(std::unique_ptr< Properties > props)
function
Gate()
function
void setRunOnHost(bool runOnHost)
Specify whether to run on host or device By default, the node will run on device.
function
bool runOnHost()
Check if the node is configured to run on the host.
Returns
true if running on host, false otherwise.
function
void run()
inline function
DeviceNodeCRTP()
inline function
DeviceNodeCRTP(const std::shared_ptr< Device > & device)
inline function
DeviceNodeCRTP(std::unique_ptr< Properties > props)
inline function
DeviceNodeCRTP(std::unique_ptr< Properties > props, bool confMode)
inline function
DeviceNodeCRTP(const std::shared_ptr< Device > & device, std::unique_ptr< Properties > props, bool confMode)

需要帮助?

请访问讨论论坛以获取技术支持或您可能有的任何其他问题。