-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathgate_example.py
More file actions
52 lines (38 loc) · 1.34 KB
/
gate_example.py
File metadata and controls
52 lines (38 loc) · 1.34 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
import time
import cv2
import depthai as dai
device = dai.Device()
withGate = True
with dai.Pipeline(device) as pipeline:
camera = pipeline.create(dai.node.Camera).build()
cameraOut = camera.requestOutput((640, 400), fps=30)
gate = pipeline.create(dai.node.Gate)
cameraOut.link(gate.input)
cameraQueue = gate.output.createOutputQueue()
gateControlQueue = gate.inputControl.createInputQueue()
gateControl = dai.GateControl()
pipeline.start()
ellapsed = 0
startTime = time.monotonic()
gateOpen = True
while pipeline.isRunning():
frame = cameraQueue.tryGet()
if frame is not None:
cv2.imshow("camera", frame.getCvFrame())
currentTime = time.monotonic()
elapsed = currentTime - startTime
if elapsed > 5.0: # 5 seconds
# Toggle the value
gateOpen = not gateOpen
# Create and send the control message
if (gateOpen):
gateControlQueue.send(dai.GateControl.openGate())
else:
gateControlQueue.send(dai.GateControl.closeGate())
print(f"Gate toggled to: {gateOpen}")
# Reset the timer
startTime = currentTime
key = cv2.waitKey(1)
if key == ord('q'):
pipeline.stop()
break