本页目录

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

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    # 每隔奇数秒打开门,偶数秒关闭门
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)

需要帮助?

请前往 OAKChina 官网 获取技术支持或解答您的任何疑问。