Pipeline
Source code
Python
PythonGitHub
1import time
2import cv2
3import depthai as dai
4
5device = dai.Device()
6
7withGate = True
8
9with dai.Pipeline(device) as pipeline:
10 camera = pipeline.create(dai.node.Camera).build()
11 cameraOut = camera.requestOutput((640, 400), fps=30)
12
13 gate = pipeline.create(dai.node.Gate)
14 cameraOut.link(gate.input)
15 cameraQueue = gate.output.createOutputQueue()
16 gateControlQueue = gate.inputControl.createInputQueue()
17
18 gateControl = dai.GateControl()
19
20 pipeline.start()
21
22 ellapsed = 0
23 startTime = time.monotonic()
24 gateOpen = True
25
26 while pipeline.isRunning():
27 frame = cameraQueue.tryGet()
28 if frame is not None:
29 cv2.imshow("camera", frame.getCvFrame())
30
31 currentTime = time.monotonic()
32 elapsed = currentTime - startTime
33
34 if elapsed > 5.0: # 5 seconds
35 # Toggle the value
36 gateOpen = not gateOpen
37 # Create and send the control message
38 if (gateOpen):
39 gateControlQueue.send(dai.GateControl.openGate())
40 else:
41 gateControlQueue.send(dai.GateControl.closeGate())
42
43 print(f"Gate toggled to: {gateOpen}")
44
45 # Reset the timer
46 startTime = currentTime
47
48 key = cv2.waitKey(1)
49
50 if key == ord('q'):
51 pipeline.stop()
52 break需要帮助?
请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。