-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathqueue_add_callback.py
More file actions
executable file
·54 lines (43 loc) · 1.59 KB
/
Copy pathqueue_add_callback.py
File metadata and controls
executable file
·54 lines (43 loc) · 1.59 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
#!/usr/bin/env python3
import cv2
import depthai as dai
import queue
# Create pipeline
pipeline = dai.Pipeline()
# Add all three cameras
camRgb = pipeline.create(dai.node.ColorCamera)
left = pipeline.create(dai.node.MonoCamera)
right = pipeline.create(dai.node.MonoCamera)
# Create XLink output
xout = pipeline.create(dai.node.XLinkOut)
xout.setStreamName("frames")
# Properties
camRgb.setPreviewSize(300, 300)
left.setCamera("left")
left.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
right.setCamera("right")
right.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
# Stream all the camera streams through the same XLink node
camRgb.preview.link(xout.input)
left.out.link(xout.input)
right.out.link(xout.input)
q = queue.Queue()
def newFrame(inFrame):
global q
# Get "stream name" from the instance number
num = inFrame.getInstanceNum()
name = "color" if num == 0 else "left" if num == 1 else "right"
frame = inFrame.getCvFrame()
# This is a different thread and you could use it to
# run image processing algorithms here
q.put({"name": name, "frame": frame})
# Connect to device and start pipeline
with dai.Device(pipeline) as device:
# Add callback to the output queue "frames" for all newly arrived frames (color, left, right)
device.getOutputQueue(name="frames", maxSize=4, blocking=False).addCallback(newFrame)
while True:
# You could also get the data as non-blocking (block=False)
data = q.get(block=True)
cv2.imshow(data["name"], data["frame"])
if cv2.waitKey(1) == ord('q'):
break