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

本页目录

  • 如何放置它
  • 输入和输出
  • 用法
  • 功能示例
  • 参考

Gate

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
variable
Output output
variable
Input inputControl
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()
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)

需要帮助?

请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。