From 2e3e8a3d6503fec62913fbed6a1b98ef064f707c Mon Sep 17 00:00:00 2001 From: jakaskerl Date: Mon, 15 Jan 2024 15:37:01 +0100 Subject: [PATCH 1/2] Added depth preview example for OAK-SR --- examples/StereoDepth/depth_preview_sr.py | 72 ++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 examples/StereoDepth/depth_preview_sr.py diff --git a/examples/StereoDepth/depth_preview_sr.py b/examples/StereoDepth/depth_preview_sr.py new file mode 100755 index 000000000..3f5cdb30d --- /dev/null +++ b/examples/StereoDepth/depth_preview_sr.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 + +import cv2 +import depthai as dai +import numpy as np + +# Closer-in minimum depth, disparity range is doubled (from 95 to 190): +extended_disparity = False +# Better accuracy for longer distance, fractional disparity 32-levels: +subpixel = True +# Better handling for occlusions: +lr_check = True + +enableRectified = True + +# Create pipeline +pipeline = dai.Pipeline() + +# Define sources and outputs +left = pipeline.create(dai.node.ColorCamera) +right = pipeline.create(dai.node.ColorCamera) + +# Create stereo +stereo = pipeline.create(dai.node.StereoDepth) +xout_depth = pipeline.create(dai.node.XLinkOut) +xout_depth.setStreamName("disparity") + +# Properties +left.setResolution(dai.ColorCameraProperties.SensorResolution.THE_800_P) +left.setCamera("left") + +right.setResolution(dai.ColorCameraProperties.SensorResolution.THE_800_P) +right.setCamera("right") + +stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY) +stereo.initialConfig.setMedianFilter(dai.MedianFilter.KERNEL_7x7) +stereo.setLeftRightCheck(lr_check) +stereo.setExtendedDisparity(extended_disparity) +stereo.setSubpixel(subpixel) + + +# Linking +left.isp.link(stereo.left) +right.isp.link(stereo.right) +if enableRectified: + xout_rect_l = pipeline.create(dai.node.XLinkOut) + xout_rect_r = pipeline.create(dai.node.XLinkOut) + xout_rect_l.setStreamName("rectifiedLeft") + xout_rect_r.setStreamName("rectifiedRight") + stereo.rectifiedLeft.link(xout_rect_l.input) + stereo.rectifiedRight.link(xout_rect_r.input) +stereo.disparity.link(xout_depth.input) + +maxDisp = stereo.initialConfig.getMaxDisparity() + +# Connect to device and start pipeline +with dai.Device(pipeline) as device: + while not device.isClosed(): + queueNames = device.getQueueEvents() + for q in queueNames: + message = device.getOutputQueue(q).get() + # Display arrived frames + if type(message) == dai.ImgFrame: + frame = message.getCvFrame() + if 'disparity' in q: + disp = (frame * (255.0 / maxDisp)).astype(np.uint8) + disp = cv2.applyColorMap(disp, cv2.COLORMAP_JET) + cv2.imshow(q, disp) + else: + cv2.imshow(q, frame) + if cv2.waitKey(1) == ord('q'): + break \ No newline at end of file From 3a322800352d22fabbbbce0dc0d66a312a13e56a Mon Sep 17 00:00:00 2001 From: jakaskerl <53253318+jakaskerl@users.noreply.github.com> Date: Mon, 15 Jan 2024 20:06:03 +0100 Subject: [PATCH 2/2] Update depth_preview_sr.py --- examples/StereoDepth/depth_preview_sr.py | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/StereoDepth/depth_preview_sr.py b/examples/StereoDepth/depth_preview_sr.py index 3f5cdb30d..6d82d6317 100755 --- a/examples/StereoDepth/depth_preview_sr.py +++ b/examples/StereoDepth/depth_preview_sr.py @@ -5,11 +5,11 @@ import numpy as np # Closer-in minimum depth, disparity range is doubled (from 95 to 190): -extended_disparity = False +extendedDisparity = False # Better accuracy for longer distance, fractional disparity 32-levels: subpixel = True # Better handling for occlusions: -lr_check = True +lrCheck = True enableRectified = True @@ -22,8 +22,8 @@ # Create stereo stereo = pipeline.create(dai.node.StereoDepth) -xout_depth = pipeline.create(dai.node.XLinkOut) -xout_depth.setStreamName("disparity") +xoutDepth = pipeline.create(dai.node.XLinkOut) +xoutDepth.setStreamName("disparity") # Properties left.setResolution(dai.ColorCameraProperties.SensorResolution.THE_800_P) @@ -34,8 +34,8 @@ stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY) stereo.initialConfig.setMedianFilter(dai.MedianFilter.KERNEL_7x7) -stereo.setLeftRightCheck(lr_check) -stereo.setExtendedDisparity(extended_disparity) +stereo.setLeftRightCheck(lrCheck) +stereo.setExtendedDisparity(extendedDisparity) stereo.setSubpixel(subpixel) @@ -43,13 +43,13 @@ left.isp.link(stereo.left) right.isp.link(stereo.right) if enableRectified: - xout_rect_l = pipeline.create(dai.node.XLinkOut) - xout_rect_r = pipeline.create(dai.node.XLinkOut) - xout_rect_l.setStreamName("rectifiedLeft") - xout_rect_r.setStreamName("rectifiedRight") - stereo.rectifiedLeft.link(xout_rect_l.input) - stereo.rectifiedRight.link(xout_rect_r.input) -stereo.disparity.link(xout_depth.input) + xoutRectR = pipeline.create(dai.node.XLinkOut) + xoutRectL= pipeline.create(dai.node.XLinkOut) + xoutRectR.setStreamName("rectifiedRight") + xoutRectL.setStreamName("rectifiedLeft") + stereo.rectifiedLeft.link(xoutRectL.input) + stereo.rectifiedRight.link(xoutRectR.input) +stereo.disparity.link(xoutDepth.input) maxDisp = stereo.initialConfig.getMaxDisparity() @@ -69,4 +69,5 @@ else: cv2.imshow(q, frame) if cv2.waitKey(1) == ord('q'): - break \ No newline at end of file + break +