Skip to content

Commit 60e9945

Browse files
authored
Added depth preview example for OAK-SR (#955)
* Added depth preview example for OAK-SR
1 parent d73694a commit 60e9945

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env python3
2+
3+
import cv2
4+
import depthai as dai
5+
import numpy as np
6+
7+
# Closer-in minimum depth, disparity range is doubled (from 95 to 190):
8+
extendedDisparity = False
9+
# Better accuracy for longer distance, fractional disparity 32-levels:
10+
subpixel = True
11+
# Better handling for occlusions:
12+
lrCheck = True
13+
14+
enableRectified = True
15+
16+
# Create pipeline
17+
pipeline = dai.Pipeline()
18+
19+
# Define sources and outputs
20+
left = pipeline.create(dai.node.ColorCamera)
21+
right = pipeline.create(dai.node.ColorCamera)
22+
23+
# Create stereo
24+
stereo = pipeline.create(dai.node.StereoDepth)
25+
xoutDepth = pipeline.create(dai.node.XLinkOut)
26+
xoutDepth.setStreamName("disparity")
27+
28+
# Properties
29+
left.setResolution(dai.ColorCameraProperties.SensorResolution.THE_800_P)
30+
left.setCamera("left")
31+
32+
right.setResolution(dai.ColorCameraProperties.SensorResolution.THE_800_P)
33+
right.setCamera("right")
34+
35+
stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
36+
stereo.initialConfig.setMedianFilter(dai.MedianFilter.KERNEL_7x7)
37+
stereo.setLeftRightCheck(lrCheck)
38+
stereo.setExtendedDisparity(extendedDisparity)
39+
stereo.setSubpixel(subpixel)
40+
41+
42+
# Linking
43+
left.isp.link(stereo.left)
44+
right.isp.link(stereo.right)
45+
if enableRectified:
46+
xoutRectR = pipeline.create(dai.node.XLinkOut)
47+
xoutRectL= pipeline.create(dai.node.XLinkOut)
48+
xoutRectR.setStreamName("rectifiedRight")
49+
xoutRectL.setStreamName("rectifiedLeft")
50+
stereo.rectifiedLeft.link(xoutRectL.input)
51+
stereo.rectifiedRight.link(xoutRectR.input)
52+
stereo.disparity.link(xoutDepth.input)
53+
54+
maxDisp = stereo.initialConfig.getMaxDisparity()
55+
56+
# Connect to device and start pipeline
57+
with dai.Device(pipeline) as device:
58+
while not device.isClosed():
59+
queueNames = device.getQueueEvents()
60+
for q in queueNames:
61+
message = device.getOutputQueue(q).get()
62+
# Display arrived frames
63+
if type(message) == dai.ImgFrame:
64+
frame = message.getCvFrame()
65+
if 'disparity' in q:
66+
disp = (frame * (255.0 / maxDisp)).astype(np.uint8)
67+
disp = cv2.applyColorMap(disp, cv2.COLORMAP_JET)
68+
cv2.imshow(q, disp)
69+
else:
70+
cv2.imshow(q, frame)
71+
if cv2.waitKey(1) == ord('q'):
72+
break
73+

0 commit comments

Comments
 (0)