Skip to content

Commit fe1ec79

Browse files
committed
Fixed some ..math docs, as sphinx is quite strange with these
1 parent d8dfcdb commit fe1ec79

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

docs/source/samples/calibration/calibration_reader.rst

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,17 @@ 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
34-
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
37-
38-
Examples for calculating the depth value, using the OAK-D (7.5cm baseline):
32+
With 400P (640x400) camera resolution where HFOV=71.9 degrees:
3933

4034
.. math::
4135
42-
# For OAK-D @ 400P resolution and disparity of eg. 50 pixels
43-
depth = 441.25 * 7.5 / 50 = 66.19 # cm
36+
focalLength = 640 * 0.5 / tan(71.9 * 0.5 * PI / 180) = 441.25
4437
45-
# For OAK-D @ 800P resolution and disparity of eg. 10 pixels
46-
depth = 882.5 * 7.5 / 10 = 661.88 # cm
38+
And for 800P (1280x800) camera resolution where HFOV=71.9 degrees:
4739

40+
focalLength = 1280 * 0.5 / tan(71.9 * 0.5 * PI / 180) = 882.5
4841

4942
Setup
5043
#####

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

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

282289
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:
290+
and seeing how there are discrete "layers" of points, instead of a smooth transition:
284291

285292
.. image:: /_static/images/components/layered-pointcloud.png
286293

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

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

298+
.. code-block:: python
299+
300+
# Number of unique values based on subpixel bits setting.
301+
Unique values = 94 * 2 ^ subpixel_bits + 2 (min/max value)
302+
291303
.. math::
292-
94 * 2^3 [subpixel bits] + 2 [min/max value] = 754 unique values
304+
94 * 2^3 + 2 = 754
293305
294306
.. math::
295-
94 * 2^4 [subpixel bits] + 2 [min/max value] = 1506 unique values
307+
94 * 2^4 + 2 = 1506
296308
297309
.. math::
298-
94 * 2^5 [subpixel bits] + 2 [min/max value] = 3010 unique values
310+
94 * 2^5 + 2 = 3010
299311
300312
One can change the number of subpixel bits by setting ``stereoDepth.setSubpixelFractionalBits(int)`` parameter to 3, 4 or 5 bits.
301313

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

319331
.. math::
320-
depth = focal_length * baseline / disparity
332+
depth = focalLength * baseline / disparity
321333
322334
.. math::
323-
MinZ = focal_length * baseline / 95
335+
MinZ = focalLength * baseline / 95
324336
325337
How to get lower MinZ
326338
---------------------
@@ -343,10 +355,10 @@ Above we have a formula for MinZ, and by lowering the resolution, we are lowerin
343355
MinZ = focalLength * baseline / 95
344356
345357
.. math::
346-
MinZ [800P OAK-D] = 882.5 * 7.5 / 95 = 70 cm
358+
MinZ [800P] = 882.5 * 7.5 / 95 = 70 cm
347359
348360
.. math::
349-
MinZ [400P OAK-D] = 441 * 7.5 / 95 = 35 cm
361+
MinZ [400P] = 441 * 7.5 / 95 = 35 cm
350362
351363
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).
352364

@@ -431,7 +443,7 @@ That gives the following formula:
431443
B = 2 * Dv * tan(HFOV/2) * W / (2 * D * tan(HFOV/2))
432444
433445
.. math::
434-
B = W * Dv / D # pixels
446+
B [pixels] = W * Dv / D
435447
436448
Example: If we are using OAK-D, which has a HFOV of 72°, a baseline (:code:`BL`) of 7.5 cm and
437449
640x400 (400P) resolution is used, therefore :code:`W = 640` and an object is :code:`D = 100` cm away, we can
@@ -440,7 +452,7 @@ calculate :code:`B` in the following way:
440452
.. math::
441453
442454
Dv = 7.5 / 2 * tan(90 - 72/2) = 3.75 * tan(54°) = 5.16 cm
443-
B = 640 * 5.16 / 100 = 33 # pixels
455+
B = 640 * 5.16 / 100 = 33
444456
445457
Credit for calculations and images goes to our community member gregflurry, which he made on
446458
`this <https://discuss.luxonis.com/d/339-naive-question-regarding-stereodepth-disparity-and-depth-outputs/7>`__

0 commit comments

Comments
 (0)