# Depth Accuracy

## Stereo Depth Accuracy

Stereo depth accuracy (Z-Accuracy) depends on number of factors that are documented at [Improving stereo
accuracy](https://docs.luxonis.com/hardware/platform/depth/configuring-stereo-depth.md#improving-depth-accuracy). In a nutshell,
the most important factors are:

Camera calibration: Accuracy results below were obtained with the default factory calibration. FOV of the camera: Wider FOV
results in less accurate depth. Resolution of stereo pair: Higher resolution results in more accurate depth. Baseline distance:
Wider baseline distance results in more accurate depth, but also higher MinZ (minimal depth distance the camera can detect).

### 800P, 75mm baseline distance OAK4-D

For normal FOV cameras with 800P ([OV9282](https://docs.luxonis.com/hardware/sensors/OV9282.md) or
[OV9782](https://docs.luxonis.com/hardware/sensors/OV9782.md)) stereo pair resolution;

[OAK4-D](https://shop.luxonis.com/products/oak-4-d?variant=46428694446303) and [OAK4-D
Pro](https://shop.luxonis.com/products/oak-4-d-ea)

Depth accuracy of a median device (in terms of depth performance) would be:

below 4m: below 1.5% absolute depth error 4m - 8m: below 3% absolute depth error 8m - 12m: below 6% absolute depth error

### 800P, 75mm baseline distance OAKs

For normal FOV cameras with 800P ([OV9282](https://docs.luxonis.com/hardware/sensors/OV9282.md) or
[OV9782](https://docs.luxonis.com/hardware/sensors/OV9782.md)) stereo pair resolution;

[OAK-D](https://docs.luxonis.com/hardware/products/OAK-D.md), [OAK-D
S2](https://docs.luxonis.com/hardware/products/OAK-D%2520S2.md), [OAK-D
Pro](https://docs.luxonis.com/hardware/products/OAK-D%2520Pro.md), [OAK-D Pro
PoE](https://docs.luxonis.com/hardware/products/OAK-D%2520Pro%2520PoE.md), [OAK-D S2
PoE](https://docs.luxonis.com/hardware/products/OAK-D%2520S2%2520PoE.md),
[OAK-D-PoE](https://docs.luxonis.com/hardware/products/OAK-D%2520PoE.md).

Depth accuracy of a median device (in terms of depth performance) would be:

below 4m: below 2% absolute depth error 4m - 7m: below 4% absolute depth error 7m - 10.5m: below 6% absolute depth error

### 480P, 75mm baseline distance OAKs

For normal FOV cameras with 480P ([OV7251](https://docs.luxonis.com/hardware/sensors/OV7251.md)) stereo pair resolution; [OAK-D
Lite](https://docs.luxonis.com/hardware/products/OAK-D%2520Lite.md).

Depth accuracy of a median device (in terms of depth performance) would be:

below 3m: below 2% absolute depth error 3m - 6m: below 4% absolute depth error 6m - 8m: below 6% absolute depth error

### 800P, Wide FOV, 75mm baseline distance OAKs

For wide FOV cameras with 800P ([OV9282](https://docs.luxonis.com/hardware/sensors/OV9282.md)) stereo pair resolution;

[OAK-D W](https://docs.luxonis.com/hardware/products/OAK-D%2520W.md), [OAK-D Pro
W](https://docs.luxonis.com/hardware/products/OAK-D%2520Pro%2520W.md), [OAK-D Pro W
PoE](https://docs.luxonis.com/hardware/products/OAK-D%2520Pro%2520W%2520PoE.md), [OAK-D W
PoE](https://docs.luxonis.com/hardware/products/OAK-D%2520W%2520PoE.md).

Depth accuracy of a median device (in terms of depth performance) would be:

below 3.5m: below 2% absolute depth error 3.5m - 6.5m: below 4% absolute depth error 6.5m - 9m: below 6% absolute depth error

### 800P, 150mm baseline distance OAK-D LR

For [OAK-D LR](https://docs.luxonis.com/hardware/products/OAK-D%2520LR.md) with
[AR0234](https://docs.luxonis.com/hardware/sensors/AR0234.md) sensors, using the widest baseline (15cm). Depth accuracy of a
median device (in terms of depth performance) would be:

below 7.5m: below 1.5% absolute depth error 7.5m - 12.5m: below 2.5% absolute depth error

> Due to stereo matching limitation of max 1280 pixels in width on
> [RVC2-based](https://docs.luxonis.com/hardware/platform/rvc/rvc2.md)
> cameras,
> `ispScale`
> was used to downscale AR0234's 1920x1200 frames to 1280x800 frames, which provides the full FOV, but with lower resolution.
Alternatively, you could middle-crop the 1920x1200 frames to get the best long-range depth accuracy (but lose some FOV).

### 800P, 20mm baseline distance OAKs

For OAK cameras with 800P ([OV9782](https://docs.luxonis.com/hardware/sensors/OV9782.md)) stereo pair resolution and 2cm stereo
baseline distance:

[OAK-D SR](https://docs.luxonis.com/hardware/products/OAK-D%2520SR.md) [OAK-D
ToF](https://docs.luxonis.com/hardware/products/OAK-D%2520ToF.md) (Also has ToF depth sensor, which typically has better accuracy)

Depth accuracy:

30cm - 1.8m: below 2% absolute depth error 1.8m - 2.8m: below 4% absolute depth error 2.8m - 4m: below 6% absolute depth error

## ToF Depth Accuracy

Compared to stereo depth error profile, ToF depth error does not (exponentially) increase with distance, but it's constant.

For this evaluation we have configured the [ToF
node](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/tof.md) as following:

 * Median filter: 5x5
 * Phase unwrapping level: 3 (max distance: 6m)
 * Phase unwrapping error threshold: 300
 * Phase shuffle temporal filter: enabled

## Accuracy comparison

We have also compared the depth accuracy of different stereo cameras with OAK-D Pro. The comparison is done with the same setup,
process, and conditions as mentioned in [Measurement setup](#Depth%2520Accuracy-Measurement%2520setup), and the results can be
seen below.

For comparison, we took accuracy of OAK-D-Pro with median depth accuracy (in terms of depth performance), and for other stereo
cameras we only have 1 of each.

Measurement data can be found on [Google
Sheets](https://docs.google.com/spreadsheets/d/1pG8wb8R004sHAuvhgR6GfD3y09QiVdntbGmob9s2Ab0), on tabs 800P,75mm (OAK-D Pro), Zed
2i, D435, and D455.

#### Parameters

We used the following parameters:

 * OAK-D Pro: Using depthai library, subpixel mode, LR-mode, and with 800P resolution. No post-processing filters.
 * RealSense™ D455 and D435: Using pyrealsense2, 720P resolution with High Accuracy preset
 * Stereolabs™ Zed 2i: Using pyzed, RESOLUTION.HD2K resolution with DEPTH_MODE.ULTRA preset.

## Measurement setup

We are using random noise pattern to measure depth accuracy, so the lighting/texture ([documentation
here](https://docs.luxonis.com/hardware/platform/depth/configuring-stereo-depth.md#scene-texture)) is near-ideal. This means that
random dot projector (on Pro versions) won't make a difference. The noise pattern board is parpendicular to the camera, and the
camera is looking at the center of the board. We are using highest stereo resolution possible, always have subpixel enabled with 5
disparity bits (to provide the best accuracy), and aren't using any [On-Device Stereo Postprocessing
Filters](https://docs.luxonis.com/software/depthai/examples/depth_post_processing.md#depth-post-processing)).

Here is the process for each step of the measurement, which is similar to how other companies measure their depth accuracy:

 1. Capture the image, find ROI of the noise pattern board (via markers)
 2. Remove invalid pixels and outliers (top/bottom 5% of values)
 3. Calculate median of remaining depth values
 4. Repeat 10 times, average the median values to remove noise

Raw data of the depth accuracy evaluation can be found on [Google Sheets
here](https://docs.google.com/spreadsheets/d/1pG8wb8R004sHAuvhgR6GfD3y09QiVdntbGmob9s2Ab0/edit?usp=sharing).

### Accuracy oscillation

From the graphs it's clear that the depth accuracy oscillates with distances. This is due to the nature of disparity matching, and
is a common thing in stereo depth cameras.

You can see data & graphs in [Gsheets
here](https://docs.google.com/spreadsheets/d/1pG8wb8R004sHAuvhgR6GfD3y09QiVdntbGmob9s2Ab0/edit#gid=1080580476) in Theoretical tab.
Let's first look at ideal measured distance (for OAK-D-Lite) at different distances:

You can see oscillation around the ground truth, easily seen for full-pixel depth (green line). Let's focus on that: there are
discrete "steps"/"stairs" in the graph. One is at 6.6m, then 8.25m, then 11m. These correspond to disparity distance of 5, 4, and
3 pixels. This means that a feature on the left stereo frame is 5/4/3 pixels to the left of the same feature on the right stereo
frame.

With Subpixel mode, you can achieve better accuracy, as we can estimate the disparity distance with higher precision, so eg. 3.5,
or 4.125 pixels. This will make estimations more accurate, but oscillation is still there.

Let's also look at the same data, but for depth error in %:

And if we look at the absolute error, the ideal 1/2 pixel accuracy (below) will look somewhat similar to the chart above ([480P,
75mm baseline distance
OAKs](#Depth%2520Accuracy-Stereo%2520Depth%2520Accuracy-480P%252C%252075mm%2520baseline%2520distance%2520OAKs)). Note that every
camera is different, and for the graph below we set focal distance to 440pix.
