Skip to content

Commit cd07f49

Browse files
committed
Started updating depth colorization logic
1 parent bfe6578 commit cd07f49

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

examples/SpatialDetection/spatial_calculator_multi_roi.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import cv2
44
import depthai as dai
55
import math
6+
import numpy as np
67

78
# Create pipeline
89
pipeline = dai.Pipeline()
@@ -29,7 +30,7 @@
2930

3031
stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
3132
stereo.setLeftRightCheck(True)
32-
stereo.setExtendedDisparity(True)
33+
stereo.setSubpixel(True)
3334
spatialLocationCalculator.inputConfig.setWaitForMessage(False)
3435

3536
# Create 10 ROIs
@@ -65,8 +66,10 @@
6566

6667
depthFrame = inDepth.getFrame() # depthFrame values are in millimeters
6768

68-
depthFrameColor = cv2.normalize(depthFrame, None, 255, 0, cv2.NORM_INF, cv2.CV_8UC1)
69-
depthFrameColor = cv2.equalizeHist(depthFrameColor)
69+
depth_downscaled = depthFrame[::4]
70+
min_depth = np.percentile(depth_downscaled[depth_downscaled != 0], 1)
71+
max_depth = np.percentile(depth_downscaled, 99)
72+
depthFrameColor = np.interp(depthFrame, (min_depth, max_depth), (0, 255)).astype(np.uint8)
7073
depthFrameColor = cv2.applyColorMap(depthFrameColor, cv2.COLORMAP_HOT)
7174

7275
spatialData = spatialCalcQueue.get().getSpatialLocations()

examples/mixed/rotated_spatial_detections.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import cv2
66
import depthai as dai
7-
7+
import numpy as np
88
'''
99
Spatial object detections demo for 180° rotated OAK camera.
1010
'''
@@ -58,6 +58,7 @@
5858
stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
5959
# Align depth map to the perspective of RGB camera, on which inference is done
6060
stereo.setDepthAlign(dai.CameraBoardSocket.RGB)
61+
stereo.setSubpixel(True)
6162
stereo.setOutputSize(monoLeft.getResolutionWidth(), monoLeft.getResolutionHeight())
6263

6364
rotate_stereo_manip = pipeline.createImageManip()
@@ -104,8 +105,10 @@
104105
frame = inPreview.getCvFrame()
105106
depthFrame = depth.getFrame() # depthFrame values are in millimeters
106107

107-
depthFrameColor = cv2.normalize(depthFrame, None, 255, 0, cv2.NORM_INF, cv2.CV_8UC1)
108-
depthFrameColor = cv2.equalizeHist(depthFrameColor)
108+
depth_downscaled = depthFrame[::4]
109+
min_depth = np.percentile(depth_downscaled[depth_downscaled != 0], 1)
110+
max_depth = np.percentile(depth_downscaled, 99)
111+
depthFrameColor = np.interp(depthFrame, (min_depth, max_depth), (0, 255)).astype(np.uint8)
109112
depthFrameColor = cv2.applyColorMap(depthFrameColor, cv2.COLORMAP_HOT)
110113

111114
detections = inDet.detections

0 commit comments

Comments
 (0)