Skip to content

Commit 4f65e78

Browse files
committed
Merge branch 'release_v2.22.0.0'
2 parents c3d9d7b + 21463dd commit 4f65e78

File tree

76 files changed

+995
-251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+995
-251
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ pybind11_add_module(${TARGET_NAME}
127127
src/pipeline/node/AprilTagBindings.cpp
128128
src/pipeline/node/DetectionParserBindings.cpp
129129
src/pipeline/node/WarpBindings.cpp
130+
src/pipeline/node/UVCBindings.cpp
131+
src/pipeline/node/ToFBindings.cpp
130132

131133
src/pipeline/datatype/ADatatypeBindings.cpp
132134
src/pipeline/datatype/AprilTagConfigBindings.cpp
@@ -135,6 +137,7 @@ pybind11_add_module(${TARGET_NAME}
135137
src/pipeline/datatype/CameraControlBindings.cpp
136138
src/pipeline/datatype/EdgeDetectorConfigBindings.cpp
137139
src/pipeline/datatype/FeatureTrackerConfigBindings.cpp
140+
src/pipeline/datatype/ToFConfigBindings.cpp
138141
src/pipeline/datatype/ImageManipConfigBindings.cpp
139142
src/pipeline/datatype/ImgDetectionsBindings.cpp
140143
src/pipeline/datatype/ImgFrameBindings.cpp

depthai-core

Submodule depthai-core updated 103 files

docs/source/components/nodes/color_camera.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Usage
8787
pipeline = dai.Pipeline()
8888
cam = pipeline.create(dai.node.ColorCamera)
8989
cam.setPreviewSize(300, 300)
90-
cam.setBoardSocket(dai.CameraBoardSocket.RGB)
90+
cam.setBoardSocket(dai.CameraBoardSocket.CAM_A)
9191
cam.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
9292
cam.setInterleaved(False)
9393
cam.setColorOrder(dai.ColorCameraProperties.ColorOrder.RGB)
@@ -97,7 +97,7 @@ Usage
9797
dai::Pipeline pipeline;
9898
auto cam = pipeline.create<dai::node::ColorCamera>();
9999
cam->setPreviewSize(300, 300);
100-
cam->setBoardSocket(dai::CameraBoardSocket::RGB);
100+
cam->setBoardSocket(dai::CameraBoardSocket::CAM_A);
101101
cam->setResolution(dai::ColorCameraProperties::SensorResolution::THE_1080_P);
102102
cam->setInterleaved(false);
103103
cam->setColorOrder(dai::ColorCameraProperties::ColorOrder::RGB);

docs/source/components/nodes/mono_camera.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ Usage
4848

4949
pipeline = dai.Pipeline()
5050
mono = pipeline.create(dai.node.MonoCamera)
51-
mono.setBoardSocket(dai.CameraBoardSocket.RIGHT)
51+
mono.setCamera("right")
5252
mono.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
5353

5454
.. code-tab:: c++
5555

5656
dai::Pipeline pipeline;
5757
auto mono = pipeline.create<dai::node::MonoCamera>();
58-
mono->setBoardSocket(dai::CameraBoardSocket::RIGHT);
58+
mono->setCamera("right");
5959
mono->setResolution(dai::MonoCameraProperties::SensorResolution::THE_720_P);
6060

6161
Examples of functionality

docs/source/components/nodes/stereo_depth.rst

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,221 @@ as:
288288
For the final disparity map, a filtering is applied based on the confidence threshold value: the pixels that have their confidence score larger than
289289
the threshold get invalidated, i.e. their disparity value is set to zero. You can set the confidence threshold with :code:`stereo.initialConfig.setConfidenceThreshold()`.
290290

291+
Calculate depth using disparity map
292+
===================================
293+
294+
Disparity and depth are inversely related. As disparity decreases, depth increases exponentially depending on baseline and focal length. Meaning, if the disparity value is close to zero, then a small change in disparity generates a large change in depth. Similarly, if the disparity value is big, then large changes in disparity do not lead to a large change in depth.
295+
296+
By considering this fact, depth can be calculated using this formula:
297+
298+
.. code-block:: python
299+
300+
depth = focal_length_in_pixels * baseline / disparity_in_pixels
301+
302+
Where baseline is the distance between two mono cameras. Note the unit used for baseline and depth is the same.
303+
304+
To get focal length in pixels, you can :ref:`read camera calibration <Calibration Reader>`, as focal length in pixels is
305+
written in camera intrinsics (``intrinsics[0][0]``):
306+
307+
.. code-block:: python
308+
309+
import depthai as dai
310+
311+
with dai.Device() as device:
312+
calibData = device.readCalibration()
313+
intrinsics = calibData.getCameraIntrinsics(dai.CameraBoardSocket.CAM_C)
314+
print('Right mono camera focal length in pixels:', intrinsics[0][0])
315+
316+
Here's theoretical calculation of the focal length in pixels:
317+
318+
.. code-block:: python
319+
320+
focal_length_in_pixels = image_width_in_pixels * 0.5 / tan(HFOV * 0.5 * PI/180)
321+
322+
# With 400P mono camera resolution where HFOV=71.9 degrees
323+
focal_length_in_pixels = 640 * 0.5 / tan(71.9 * 0.5 * PI / 180) = 441.25
324+
325+
# With 800P mono camera resolution where HFOV=71.9 degrees
326+
focal_length_in_pixels = 1280 * 0.5 / tan(71.9 * 0.5 * PI / 180) = 882.5
327+
328+
Examples for calculating the depth value, using the OAK-D (7.5cm baseline):
329+
330+
.. code-block:: python
331+
332+
# For OAK-D @ 400P mono cameras and disparity of eg. 50 pixels
333+
depth = 441.25 * 7.5 / 50 = 66.19 # cm
334+
335+
# For OAK-D @ 800P mono cameras and disparity of eg. 10 pixels
336+
depth = 882.5 * 7.5 / 10 = 661.88 # cm
337+
338+
Note the value of disparity depth data is stored in :code:`uint16`, where 0 is a special value, meaning that distance is unknown.
339+
340+
Min stereo depth distance
341+
=========================
342+
343+
If the depth results for close-in objects look weird, this is likely because they are below the minimum depth-perception distance of the device.
344+
345+
To calculate this minimum distance, use the :ref:`depth formula <Calculate depth using disparity map>` and choose the maximum value for disparity_in_pixels parameter (keep in mind it is inveresly related, so maximum value will yield the smallest result).
346+
347+
For example OAK-D has a baseline of **7.5cm**, focal_length_in_pixels of **882.5 pixels** and the default maximum value for disparity_in_pixels is **95**. By using the :ref:`depth formula <Calculate depth using disparity map>` we get:
348+
349+
.. code-block:: python
350+
351+
min_distance = focal_length_in_pixels * baseline / disparity_in_pixels = 882.5 * 7.5cm / 95 = 69.67cm
352+
353+
or roughly 70cm.
354+
355+
However this distance can be cut in 1/2 (to around 35cm for the OAK-D) with the following options:
356+
357+
1. Changing the resolution to 640x400, instead of the standard 1280x800.
358+
359+
2. Enabling Extended Disparity.
360+
361+
Extended Disparity mode increases the levels of disparity to 191 from the standard 96 pixels, thereby 1/2-ing the minimum depth. It does so by computing the 96-pixel disparities on the original 1280x720 and on the downscaled 640x360 image, which are then merged to a 191-level disparity. For more information see the Extended Disparity tab in :ref:`this table <Currently configurable blocks>`.
362+
363+
Using the previous OAK-D example, disparity_in_pixels now becomes **190** and the minimum distance is:
364+
365+
.. code-block:: python
366+
367+
min_distance = focal_length_in_pixels * baseline / disparity_in_pixels = 882.5 * 7.5cm / 190 = 34.84cm
368+
369+
or roughly 35cm.
370+
371+
.. note::
372+
373+
Applying both of those options is possible, which would set the minimum depth to 1/4 of the standard settings, but at such short distances the minimum depth is limited by focal length, which is 19.6cm, since OAK-D mono cameras have fixed focus distance: 19.6cm - infinity.
374+
375+
See `these examples <https://github.com/luxonis/depthai-experiments/tree/master/gen2-camera-demo#real-time-depth-from-depthai-stereo-pair>`__ for how to enable Extended Disparity.
376+
377+
Disparity shift to lower min depth perception
378+
---------------------------------------------
379+
380+
Another option to perceive closer depth range is to use disparity shift. Disparity shift will shift the starting point
381+
of the disparity search, which will significantly decrease max depth (MazZ) perception, but it will also decrease min depth (MinZ) perception.
382+
Disparity shift can be combined with extended/subpixel/LR-check modes.
383+
384+
.. image:: https://user-images.githubusercontent.com/18037362/189375017-2fa137d2-ad6b-46de-8899-6304bbc6c9d7.png
385+
386+
**Left graph** shows min and max disparity and depth for OAK-D (7.5cm baseline, 800P resolution, ~70° HFOV) by default (disparity shift=0). See :ref:`Calculate depth using disparity map`.
387+
Since hardware (stereo block) has a fixed 95 pixel disparity search, DepthAI will search from 0 pixels (depth=INF) to 95 pixels (depth=71cm).
388+
389+
**Right graph** shows the same, but at disparity shift set to 30 pixels. This means that disparity search will be from 30 pixels (depth=2.2m) to 125 pixels (depth=50cm).
390+
This also means that depth will be very accurate at the short range (**theoretically** below 5mm depth error).
391+
392+
**Limitations**:
393+
394+
- Because of the inverse relationship between disparity and depth, MaxZ will decrease much faster than MinZ as the disparity shift is increased. Therefore, it is **advised not to use a larger than necessary disparity shift**.
395+
- Tradeoff in reducing the MinZ this way is that objects at **distances farther away than MaxZ will not be seen**.
396+
- Because of the point above, **we only recommend using disparity shift when MaxZ is known**, such as having a depth camera mounted above a table pointing down at the table surface.
397+
- Output disparity map is not expanded, only the depth map. So if disparity shift is set to 50, and disparity value obtained is 90, the real disparity is 140.
398+
399+
**Compared to Extended disparity**, disparity shift:
400+
401+
- **(+)** Is faster, as it doesn't require an extra computation, which means there's also no extra latency
402+
- **(-)** Reduces the MaxZ (significantly), while extended disparity only reduces MinZ.
403+
404+
Disparity shift can be combined with extended disparity.
405+
406+
.. doxygenfunction:: dai::StereoDepthConfig::setDisparityShift
407+
:project: depthai-core
408+
:no-link:
409+
410+
Max stereo depth distance
411+
=========================
412+
413+
The maximum depth perception distance depends on the :ref:`accuracy of the depth perception <Depth perception accuracy>`. The formula used to calculate this distance is an approximation, but is as follows:
414+
415+
.. code-block:: python
416+
417+
Dm = (baseline/2) * tan((90 - HFOV / HPixels)*pi/180)
418+
419+
So using this formula for existing models the *theoretical* max distance is:
420+
421+
.. code-block:: python
422+
423+
# For OAK-D (7.5cm baseline)
424+
Dm = (7.5/2) * tan((90 - 71.9/1280)*pi/180) = 3825.03cm = 38.25 meters
425+
426+
# For OAK-D-CM4 (9cm baseline)
427+
Dm = (9/2) * tan((90 - 71.9/1280)*pi/180) = 4590.04cm = 45.9 meters
428+
429+
If greater precision for long range measurements is required, consider enabling Subpixel Disparity or using a larger baseline distance between mono cameras. For a custom baseline, you could consider using `OAK-FFC <https://docs.luxonis.com/projects/hardware/en/latest/pages/DM1090.html>`__ device or design your own baseboard PCB with required baseline. For more information see Subpixel Disparity under the Stereo Mode tab in :ref:`this table <Currently configurable blocks>`.
430+
431+
Depth perception accuracy
432+
=========================
433+
434+
Disparity depth works by matching features from one image to the other and its accuracy is based on multiple parameters:
435+
436+
* Texture of objects / backgrounds
437+
438+
Backgrounds may interfere with the object detection, since backgrounds are objects too, which will make depth perception less accurate. So disparity depth works very well outdoors as there are very rarely perfectly-clean/blank surfaces there - but these are relatively commonplace indoors (in clean buildings at least).
439+
440+
* Lighting
441+
442+
If the illumination is low, the diparity map will be of low confidence, which will result in a noisy depth map.
443+
444+
* Baseline / distance to objects
445+
446+
Lower baseline enables us to detect the depth at a closer distance as long as the object is visible in both the frames. However, this reduces the accuracy for large distances due to less pixels representing the object and disparity decreasing towards 0 much faster.
447+
So the common norm is to adjust the baseline according to how far/close we want to be able to detect objects.
448+
449+
Limitation
450+
==========
451+
452+
Since depth is calculated from disparity, which requires the pixels to overlap, there is inherently a vertical
453+
band on the left side of the left mono camera and on the right side of the right mono camera, where depth
454+
cannot be calculated, since it is seen by only 1 camera. That band is marked with :code:`B`
455+
on the following picture.
456+
457+
.. image:: https://user-images.githubusercontent.com/59799831/135310921-67726c28-07e7-4ffa-bc8d-74861049517e.png
458+
459+
Meaning of variables on the picture:
460+
461+
- ``BL [cm]`` - Baseline of stereo cameras.
462+
- ``Dv [cm]`` - Minimum distace where both cameras see an object (thus where depth can be calculated).
463+
- ``B [pixels]`` - Width of the band where depth cannot be calculated.
464+
- ``W [pixels]`` - Width of mono in pixels camera or amount of horizontal pixels, also noted as :code:`HPixels` in other formulas.
465+
- ``D [cm]`` - Distance from the **camera plane** to an object (see image :ref:`here <Measuring real-world object dimensions>`).
466+
- ``F [cm]`` - Width of image at the distance ``D``.
467+
468+
.. image:: https://user-images.githubusercontent.com/59799831/135310972-c37ba40b-20ad-4967-92a7-c71078bcef99.png
469+
470+
With the use of the :code:`tan` function, the following formulas can be obtained:
471+
472+
- :code:`F = 2 * D * tan(HFOV/2)`
473+
- :code:`Dv = (BL/2) * tan(90 - HFOV/2)`
474+
475+
In order to obtain :code:`B`, we can use :code:`tan` function again (same as for :code:`F`), but this time
476+
we must also multiply it by the ratio between :code:`W` and :code:`F` in order to convert units to pixels.
477+
That gives the following formula:
478+
479+
.. code-block:: python
480+
481+
B = 2 * Dv * tan(HFOV/2) * W / F
482+
B = 2 * Dv * tan(HFOV/2) * W / (2 * D * tan(HFOV/2))
483+
B = W * Dv / D # pixels
484+
485+
Example: If we are using OAK-D, which has a :code:`HFOV` of 72°, a baseline (:code:`BL`) of 7.5 cm and
486+
:code:`640x400 (400P)` resolution is used, therefore :code:`W = 640` and an object is :code:`D = 100` cm away, we can
487+
calculate :code:`B` in the following way:
488+
489+
.. code-block::
490+
491+
Dv = 7.5 / 2 * tan(90 - 72/2) = 3.75 * tan(54°) = 5.16 cm
492+
B = 640 * 5.16 / 100 = 33 # pixels
493+
494+
Credit for calculations and images goes to our community member gregflurry, which he made on
495+
`this <https://discuss.luxonis.com/d/339-naive-question-regarding-stereodepth-disparity-and-depth-outputs/7>`__
496+
forum post.
497+
498+
.. note::
499+
500+
OAK-D-PRO will include both IR dot projector and IR LED, which will enable operation in no light.
501+
IR LED is used to illuminate the whole area (for mono/color frames), while IR dot projector is mostly
502+
for accurate disparity matching - to have good quality depth maps on blank surfaces as well. For outdoors,
503+
the IR laser dot projector is only relevant at night. For more information see the development progress
504+
`here <https://github.com/luxonis/depthai-hardware/issues/114>`__.
505+
291506
Measuring real-world object dimensions
292507
======================================
293508

docs/source/samples/host_side/device_information.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Demo
2424
Found device '192.168.33.192', MxId: '1844301011F4C51200', State: 'BOOTLOADER'
2525
2626
Booting the first available camera (1.3)...
27-
Available camera sensors: {<CameraBoardSocket.RIGHT: 2>: 'OV9282', <CameraBoardSocket.RGB: 0>: 'IMX378', <CameraBoardSocket.LEFT: 1>: 'OV9282'}
27+
Available camera sensors: {<CameraBoardSocket.CAM_C: 2>: 'OV9282', <CameraBoardSocket.CAM_A: 0>: 'IMX378', <CameraBoardSocket.CAM_B: 1>: 'OV9282'}
2828
Product name: OAK-D Pro AF, board name DM9098
2929
3030

examples/AprilTag/apriltag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
# Properties
2121
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
22-
monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT)
22+
monoLeft.setCamera("left")
2323

2424
aprilTag.initialConfig.setFamily(dai.AprilTagConfig.Family.TAG_36H11)
2525

examples/AprilTag/apriltag_rgb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
# Properties
2222
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
23-
camRgb.setBoardSocket(dai.CameraBoardSocket.RGB)
23+
camRgb.setBoardSocket(dai.CameraBoardSocket.CAM_A)
2424

2525
manip.initialConfig.setResize(480, 270)
2626
manip.initialConfig.setFrameType(dai.ImgFrame.Type.GRAY8)

examples/ColorCamera/rgb_isp_scale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
xoutVideo.setStreamName("video")
1414

1515
# Properties
16-
camRgb.setBoardSocket(dai.CameraBoardSocket.RGB)
16+
camRgb.setBoardSocket(dai.CameraBoardSocket.CAM_A)
1717
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_4_K)
1818
camRgb.setIspScale(1, 2)
1919
camRgb.setVideoSize(1920, 1080)

examples/ColorCamera/rgb_undistort.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44

55
camRes = dai.ColorCameraProperties.SensorResolution.THE_1080_P
6-
camSocket = dai.CameraBoardSocket.RGB
6+
camSocket = dai.CameraBoardSocket.CAM_A
77
ispScale = (1,2)
88

99
def getMesh(calibData, ispSize):

0 commit comments

Comments
 (0)