Skip to content

Commit 677cddf

Browse files
committed
fixed normalization in demo 03
1 parent f9b3c48 commit 677cddf

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

examples/03_depth_preview.py

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44
import depthai as dai
55
import numpy as np
66

7+
8+
'''
9+
If one or more of the additional depth modes (lrcheck, extended, subpixel)
10+
are enabled, then:
11+
- depth output is FP16. TODO enable U16.
12+
- median filtering is disabled on device. TODO enable.
13+
- with subpixel, either depth or disparity has valid data.
14+
Otherwise, depth output is U16 (mm) and median is functional.
15+
But like on Gen1, either depth or disparity has valid data. TODO enable both.
16+
'''
17+
18+
# Closer-in minimum depth, disparity range is doubled (from 95 to 190):
19+
extended_disparity = False
20+
# Better accuracy for longer distance, fractional disparity 32-levels:
21+
subpixel = False
22+
# Better handling for occlusions:
23+
lr_check = False
24+
725
# Start defining a pipeline
826
pipeline = dai.Pipeline()
927

@@ -19,25 +37,25 @@
1937
# Create a node that will produce the depth map (using disparity output as it's easier to visualize depth this way)
2038
depth = pipeline.createStereoDepth()
2139
depth.setConfidenceThreshold(200)
40+
depth.setOutputDepth(False)
2241
# Options: MEDIAN_OFF, KERNEL_3x3, KERNEL_5x5, KERNEL_7x7 (default)
2342
median = dai.StereoDepthProperties.MedianFilter.KERNEL_7x7 # For depth filtering
2443
depth.setMedianFilter(median)
2544

26-
'''
27-
If one or more of the additional depth modes (lrcheck, extended, subpixel)
28-
are enabled, then:
29-
- depth output is FP16. TODO enable U16.
30-
- median filtering is disabled on device. TODO enable.
31-
- with subpixel, either depth or disparity has valid data.
32-
Otherwise, depth output is U16 (mm) and median is functional.
33-
But like on Gen1, either depth or disparity has valid data. TODO enable both.
34-
'''
35-
# Better handling for occlusions:
36-
depth.setLeftRightCheck(False)
37-
# Closer-in minimum depth, disparity range is doubled:
38-
depth.setExtendedDisparity(False)
39-
# Better accuracy for longer distance, fractional disparity 32-levels:
40-
depth.setSubpixel(False)
45+
depth.setLeftRightCheck(lr_check)
46+
47+
# Normal disparity values range from 0..95, will be used for normalization
48+
max_disparity = 95
49+
50+
if extended_disparity: max_disparity *= 2 # Double the range
51+
depth.setExtendedDisparity(extended_disparity)
52+
53+
if subpixel: max_disparity *= 32 # 5 fractional bits, x32
54+
depth.setSubpixel(subpixel)
55+
56+
# When we get disparity to the host, we will multiply all values with the multiplier
57+
# for better visualization
58+
multiplier = 255 / max_disparity
4159

4260
left.out.link(depth.left)
4361
right.out.link(depth.right)
@@ -54,12 +72,10 @@
5472

5573
# Output queue will be used to get the disparity frames from the outputs defined above
5674
q = device.getOutputQueue(name="disparity", maxSize=4, blocking=False)
57-
5875
while True:
5976
inDepth = q.get() # blocking call, will wait until a new data has arrived
6077
frame = inDepth.getFrame()
61-
frame = cv2.normalize(frame, None, 0, 255, cv2.NORM_MINMAX)
62-
78+
frame = (frame*multiplier).astype(np.uint8)
6379
# Available color maps: https://docs.opencv.org/3.4/d3/d50/group__imgproc__colormap.html
6480
frame = cv2.applyColorMap(frame, cv2.COLORMAP_JET)
6581

0 commit comments

Comments
 (0)