-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathgate_example.cpp
More file actions
59 lines (41 loc) · 1.53 KB
/
gate_example.cpp
File metadata and controls
59 lines (41 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <chrono>
#include <iostream>
// DepthAI and OpenCV headers
#include <opencv2/opencv.hpp>
#include "depthai/depthai.hpp"
#include "depthai/pipeline/node/Gate.hpp"
int main() {
dai::Pipeline pipeline;
auto camera = pipeline.create<dai::node::Camera>()->build();
auto cameraOut = camera->requestOutput(std::make_pair(640, 400), std::nullopt, dai::ImgResizeMode::CROP, 30);
auto gate = pipeline.create<dai::node::Gate>();
cameraOut->link(gate->input);
auto cameraQueue = gate->output.createOutputQueue();
auto gateControlQueue = gate->inputControl.createInputQueue();
pipeline.start();
auto startTime = std::chrono::steady_clock::now();
bool openGate = true;
while(pipeline.isRunning()) {
auto frame = cameraQueue->tryGet<dai::ImgFrame>();
if(frame != nullptr) {
cv::imshow("camera", frame->getCvFrame());
}
auto currentTime = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsed = currentTime - startTime;
if(elapsed.count() > 5.0) {
openGate = !openGate;
if(openGate) {
gateControlQueue->send(dai::GateControl::openGate());
} else {
gateControlQueue->send(dai::GateControl::closeGate());
}
std::cout << "Gate toggled to: " << (openGate ? "True" : "False") << std::endl;
startTime = currentTime;
}
int key = cv::waitKey(1);
if(key == 'q') {
break;
}
}
return 0;
}