Skip to content

Commit 2e775d7

Browse files
authored
Merge pull request #783 from luxonis/docs_math_fix
Fixed some ..math docs, as sphinx is quite strange with these
2 parents d8dfcdb + 8187862 commit 2e775d7

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

docs/source/samples/calibration/calibration_reader.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ Here's theoretical calculation of the focal length in pixels:
2727

2828
.. math::
2929
30-
focal_length_in_pixels = image_width_in_pixels * 0.5 / tan(HFOV * 0.5 * PI/180)
30+
focalLength = width_px * 0.5 / tan(hfov * 0.5 * pi / 180)
3131
32-
// With 400P mono camera resolution where HFOV=71.9 degrees
33-
focal_length_in_pixels = 640 * 0.5 / tan(71.9 * 0.5 * PI / 180) = 441.25
32+
To get the HFOV you can use `this script <https://gist.github.com/Erol444/4aff71f4576637624d56dce4a60ad62e>`__, which also works for wide-FOV cameras and allows you to
33+
specif alpha parameter.
3434

35-
// With 800P mono camera resolution where HFOV=71.9 degrees
36-
focal_length_in_pixels = 1280 * 0.5 / tan(71.9 * 0.5 * PI / 180) = 882.5
35+
With 400P (640x400) camera resolution where HFOV=71.9 degrees:
3736

38-
Examples for calculating the depth value, using the OAK-D (7.5cm baseline):
37+
.. math::
38+
39+
focalLength = 640 * 0.5 / tan(71.9 * 0.5 * PI / 180) = 441.25
40+
41+
And for 800P (1280x800) camera resolution where HFOV=71.9 degrees:
3942

4043
.. math::
4144
42-
# For OAK-D @ 400P resolution and disparity of eg. 50 pixels
43-
depth = 441.25 * 7.5 / 50 = 66.19 # cm
45+
focalLength = 1280 * 0.5 / tan(71.9 * 0.5 * PI / 180) = 882.5
4446
45-
# For OAK-D @ 800P resolution and disparity of eg. 10 pixels
46-
depth = 882.5 * 7.5 / 10 = 661.88 # cm
4747
4848
4949
Setup

docs/source/tutorials/configuring-stereo-depth.rst

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ Let's first look at how the depth is calculated:
3636
3737
depth [mm] = focalLength [pix] * baseline [mm] / disparity [pix]
3838
39+
Examples for calculating the depth value, using the OAK-D (7.5cm baseline OV9282), for 400P resolution and disparity of 50 pixels:
40+
41+
.. math::
42+
43+
depth = 441.25 * 7.5 / 50 = 66.19 cm
3944
4045
`RVC2 <https://docs.luxonis.com/projects/hardware/en/latest/pages/rvc/rvc2.html>`__-based cameras have a **0..95 disparity search** range,
4146
which limits the minimal depth perception. Baseline is the distance between two cameras of the
@@ -280,22 +285,27 @@ Stereo subpixel effect on layering
280285
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
281286

282287
Default stereo depth output has 0..95 disparity pixels, which would produce 96 unique depth values. This can especially be seen when using pointcloud representation
283-
and seeing how there are discrete "layers" of points, instead of a smooth transition:
288+
and seeing how there are discrete "layers" of points, instead of a smooth transition:
284289

285290
.. image:: /_static/images/components/layered-pointcloud.png
286291

287292
This layering can especially be seen at longer distances, where these layers are exponentially further apart.
288293

289294
But with Stereo Subpixel mode enabled, there are many more unique values possible, which produces more granular depth steps, and thus smoother a pointcloud.
290295

296+
.. code-block:: python
297+
298+
# Number of unique values based on subpixel bits setting
299+
unique_values = 94 * 2 ^ subpixel_bits + 2 [min/max value]
300+
291301
.. math::
292-
94 * 2^3 [subpixel bits] + 2 [min/max value] = 754 unique values
302+
94 * 2^3 + 2 = 754
293303
294304
.. math::
295-
94 * 2^4 [subpixel bits] + 2 [min/max value] = 1506 unique values
305+
94 * 2^4 + 2 = 1506
296306
297307
.. math::
298-
94 * 2^5 [subpixel bits] + 2 [min/max value] = 3010 unique values
308+
94 * 2^5 + 2 = 3010
299309
300310
One can change the number of subpixel bits by setting ``stereoDepth.setSubpixelFractionalBits(int)`` parameter to 3, 4 or 5 bits.
301311

@@ -317,10 +327,10 @@ Going back to :ref:`Depth from disparity`, minimal depth perception (**MinZ**) i
317327
(maximum number of pixel for disparity search):
318328

319329
.. math::
320-
depth = focal_length * baseline / disparity
330+
depth = focalLength * baseline / disparity
321331
322332
.. math::
323-
MinZ = focal_length * baseline / 95
333+
MinZ = focalLength * baseline / 95
324334
325335
How to get lower MinZ
326336
---------------------
@@ -343,10 +353,10 @@ Above we have a formula for MinZ, and by lowering the resolution, we are lowerin
343353
MinZ = focalLength * baseline / 95
344354
345355
.. math::
346-
MinZ [800P OAK-D] = 882.5 * 7.5 / 95 = 70 cm
356+
MinZ [800P] = 882.5 * 7.5 / 95 = 70 cm
347357
348358
.. math::
349-
MinZ [400P OAK-D] = 441 * 7.5 / 95 = 35 cm
359+
MinZ [400P] = 441 * 7.5 / 95 = 35 cm
350360
351361
As you can see, by lowering resolution by 2, we are also lowering MinZ by 2. Note that because you have fewer pixels, you will also have lower depth accuracy (in cm).
352362

@@ -431,7 +441,7 @@ That gives the following formula:
431441
B = 2 * Dv * tan(HFOV/2) * W / (2 * D * tan(HFOV/2))
432442
433443
.. math::
434-
B = W * Dv / D # pixels
444+
B [pixels] = W * Dv / D
435445
436446
Example: If we are using OAK-D, which has a HFOV of 72°, a baseline (:code:`BL`) of 7.5 cm and
437447
640x400 (400P) resolution is used, therefore :code:`W = 640` and an object is :code:`D = 100` cm away, we can
@@ -440,7 +450,7 @@ calculate :code:`B` in the following way:
440450
.. math::
441451
442452
Dv = 7.5 / 2 * tan(90 - 72/2) = 3.75 * tan(54°) = 5.16 cm
443-
B = 640 * 5.16 / 100 = 33 # pixels
453+
B = 640 * 5.16 / 100 = 33
444454
445455
Credit for calculations and images goes to our community member gregflurry, which he made on
446456
`this <https://discuss.luxonis.com/d/339-naive-question-regarding-stereodepth-disparity-and-depth-outputs/7>`__
@@ -468,6 +478,7 @@ For noisy pointcloud we suggest a few approaches:
468478

469479
* (mentioned above) Start with the :ref:`Fixing noisy depth <2. Fixing noisy depth>` chapter, as otherwise, noise will produce points all over the pointcloud
470480
* (mentioned above) Continue with the :ref:`Improving depth accuracy <3. Improving depth accuracy>` chapter - depth inaccuracy will be easily visible in pointcloud
481+
471482
* Enable Stereo subpixel mode, especially due to the :ref:`Stereo subpixel effect on layering`
472483

473484
* :ref:`Decimation filter for pointcloud` for faster processing (FPS) and additional filtering

0 commit comments

Comments
 (0)