|
4 | 4 | import depthai as dai |
5 | 5 | import numpy as np |
6 | 6 |
|
| 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 | + |
7 | 25 | # Start defining a pipeline |
8 | 26 | pipeline = dai.Pipeline() |
9 | 27 |
|
|
19 | 37 | # Create a node that will produce the depth map (using disparity output as it's easier to visualize depth this way) |
20 | 38 | depth = pipeline.createStereoDepth() |
21 | 39 | depth.setConfidenceThreshold(200) |
| 40 | +depth.setOutputDepth(False) |
22 | 41 | # Options: MEDIAN_OFF, KERNEL_3x3, KERNEL_5x5, KERNEL_7x7 (default) |
23 | 42 | median = dai.StereoDepthProperties.MedianFilter.KERNEL_7x7 # For depth filtering |
24 | 43 | depth.setMedianFilter(median) |
25 | 44 |
|
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 |
41 | 59 |
|
42 | 60 | left.out.link(depth.left) |
43 | 61 | right.out.link(depth.right) |
|
54 | 72 |
|
55 | 73 | # Output queue will be used to get the disparity frames from the outputs defined above |
56 | 74 | q = device.getOutputQueue(name="disparity", maxSize=4, blocking=False) |
57 | | - |
58 | 75 | while True: |
59 | 76 | inDepth = q.get() # blocking call, will wait until a new data has arrived |
60 | 77 | frame = inDepth.getFrame() |
61 | | - frame = cv2.normalize(frame, None, 0, 255, cv2.NORM_MINMAX) |
62 | | - |
| 78 | + frame = (frame*multiplier).astype(np.uint8) |
63 | 79 | # Available color maps: https://docs.opencv.org/3.4/d3/d50/group__imgproc__colormap.html |
64 | 80 | frame = cv2.applyColorMap(frame, cv2.COLORMAP_JET) |
65 | 81 |
|
|
0 commit comments