# NeuralDepth

NeuralDepth 节点使用神经网络而非传统立体匹配算法，从立体相机对计算深度。 它提供了
[StereoDepth](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/stereo_depth.md) 节点的替代方案，具有其独特的优势。

它在底层使用 LENS (Luxonis Edge Neural Stereo)，这是一个完全在设备上的神经立体模型，针对低纹理表面、重复图案和困难光照等具有挑战性的场景进行了优化。更多背景信息，请参阅
[LENS介绍文章](https://discuss.luxonis.com/blog/6553-neural-stereo-depth-estimation-with-lens) 和 [DepthAI 3.6.1
性能更新](https://discuss.luxonis.com/blog/6837-massive-fps-boosts-for-luxonis-edge-neural-stereo-lens)。

> NeuralDepth 仅支持安装有
> **Luxonis OS 1.20.4 或更新版本**
> 的
> **RVC4**
> 设备。

## 如何放置

#### Python

```python
pipeline = dai.Pipeline()
neuralDepth = pipeline.create(dai.node.NeuralDepth)
```

#### C++

```cpp
dai::Pipeline pipeline;
auto neuralDepth = pipeline.create<dai::node::NeuralDepth>();
```

## 输入和输出

## 模型尺寸

NeuralDepth 支持多种模型尺寸，从高分辨率 XL 变体到低延迟实时预设。下面的 FPS 数据反映了在 DepthAI 3.6.1 中引入的优化模型。这些新增功能使您可以根据应用更轻松地权衡深度分辨率、精度和实时性能。

| 模型 | 分辨率 | FPS |
| --- | --- | --- |
| `NEURAL_DEPTH_1248X780` (`NEURAL_DEPTH_EXTRA_LARGE`) | 1248x780 | 8.5 |
| `NEURAL_DEPTH_1056X660` | 1056x660 | 12.5 |
| `NEURAL_DEPTH_960X600` | 960x600 | 14 |
| `NEURAL_DEPTH_864X540` | 864x540 | 18 |
| `NEURAL_DEPTH_LARGE` | 768x480 | 22 |
| `NEURAL_DEPTH_MEDIUM` | 576x360 | 38 |
| `NEURAL_DEPTH_SMALL` （默认） | 480x300 | 56 |
| `NEURAL_DEPTH_NANO` | 384x240 | 85 |

## 后处理

NeuralDepth 提供了几种后处理选项以提高深度质量：

 * 置信度阈值：置信度低于此阈值的像素被视为无效。有效范围是 [0, 255]，默认值为 125。
 * 边缘阈值：边缘幅度低于此值的像素被视为无效。有效范围是 [0, 255]，默认值为 10。
 * 时间滤波器：随时间平均深度值以降低噪声。该滤波器具有以下参数：
   * enable：布尔值，启用/禁用滤波器（默认：false）
   * alpha：指数移动平均平滑因子，范围 [0, 1]。较低的值提供更平滑的效果（对静态场景很有用），值为 1.0 时实际上相当于直通（默认：0.4）
   * delta：视差变化检测的阈值，范围 [0, 255]。只有视差变化（当前帧与前一帧之间）低于此值的像素才会被滤波，否则该像素的滤波被禁用（默认：100）

## Rectification

NeuralDepth包含一个内部矫正步骤。如果您的输入图像已经矫正过，您可以使用 setRectification(false) 禁用它。

## Usage

#### Python

```python
import depthai as dai

pipeline = dai.Pipeline()

# Create mono cameras
monoLeft = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
monoRight = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C)

# Create Outputs
leftOutput = monoLeft.requestOutput((640, 400))
rightOutput = monoRight.requestOutput((640, 400))

# Create NeuralDepth node
neuralDepth = pipeline.create(dai.node.NeuralDepth)
neuralDepth.build(leftOutput, rightOutput, dai.DeviceModelZoo.NEURAL_DEPTH_SMALL)

# Configure post-processing
neuralDepth.initialConfig.setConfidenceThreshold(125)
neuralDepth.initialConfig.setEdgeThreshold(10)

neuralDepth.initialConfig.postProcessing.temporalFilter.enable = True
neuralDepth.initialConfig.postProcessing.temporalFilter.delta = 100
neuralDepth.initialConfig.postProcessing.temporalFilter.alpha = 0.4

# Create output queue
depthQueue = neuralDepth.depth.createOutputQueue()
```

#### C++

```cpp
dai::Pipeline pipeline;

// Create mono cameras
auto monoLeft = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_B);
auto monoRight = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_C);

// Create outputs
auto leftOutput = monoLeft->requestOutput(std::make_pair(640, 400));
auto rightOutput = monoRight->requestOutput(std::make_pair(640, 400));

// Create NeuralDepth node
auto neuralDepth = pipeline.create<dai::node::NeuralDepth>();
neuralDepth->build(leftOutput, rightOutput, dai::DeviceModelZoo::NEURAL_DEPTH_SMALL);

// Configure post-processing
neuralDepth->initialConfig.setConfidenceThreshold(125);
neuralDepth->initialConfig.setEdgeThreshold(10);

neuralDepth->initialConfig.postProcessing.temporalFilter.enable = true;
neuralDepth->initialConfig.postProcessing.temporalFilter.delta = 100;
neuralDepth->initialConfig.postProcessing.temporalFilter.alpha = 0.4f;

// Create output queue
auto depthQueue = neuralDepth->depth.createOutputQueue();
```

## Examples of functionality

 * [Neural Depth Minimal](https://docs.luxonis.com/software-v3/depthai/examples/neural_depth/neural_depth_minimal.md) - 最小示例，展示基本
   NeuralDepth 用法及视差输出可视化。
 * [Neural Depth](https://docs.luxonis.com/software-v3/depthai/examples/neural_depth/neural_depth.md) - 演示 NeuralDepth
   节点，支持运行时配置置信度阈值、边缘阈值和时间滤波。
 * [Neural Depth RGBD](https://docs.luxonis.com/software-v3/depthai/examples/neural_depth/neural_depth_rgbd.md) - 将 NeuralDepth 与
   RGBD 节点结合生成点云，可通过远程连接查看。
 * [Neural Depth Align](https://docs.luxonis.com/software-v3/depthai/examples/neural_depth/neural_depth_align.md) - 演示使用
   ImageAlign 节点将 NeuralDepth 输出对齐到 RGB 相机。

## Reference

### dai::node::NeuralDepth

Kind: class

NeuralDepth node. Compute depth from left-right image pair using neural network.

#### std::shared_ptr< NeuralDepthConfig > initialConfig

Kind: variable

Initial config to use for NeuralDepth .

#### Subnode < Sync > sync

Kind: variable

#### Subnode < MessageDemux > messageDemux

Kind: variable

#### Subnode < Rectification > rectification

Kind: variable

#### Subnode < NeuralNetwork > neuralNetwork

Kind: variable

#### Input & left

Kind: variable

Input for left ImgFrame of left-right pair

#### Input & right

Kind: variable

Input for right ImgFrame of left-right pair

#### Output & rectifiedLeft

Kind: variable

Output for rectified left ImgFrame

#### Output & rectifiedRight

Kind: variable

Output for rectified right ImgFrame

#### Input inputConfig

Kind: variable

Input config to modify parameters in runtime.

#### Input nnDataInput

Kind: variable

Input NNData to parse

#### Input leftInternal

Kind: variable

Input left frame internal, used to extract frame info

#### Input rightInternal

Kind: variable

Input right frame internal, used to extract frame info

#### Output disparity

Kind: variable

Output disparity ImgFrame

#### Output depth

Kind: variable

Output depth ImgFrame

#### Output edge

Kind: variable

Output edge ImgFrame

#### Output confidence

Kind: variable

Output confidence ImgFrame

#### NeuralDepth()

Kind: function

#### NeuralDepth & setRectification(bool enable)

Kind: function

Enable or disable rectification (useful for prerectified inputs)

#### std::shared_ptr< NeuralDepth > build(Output & left, Output & right, DeviceModelZoo model)

Kind: function

#### void buildInternal()

Kind: function

Function called from within the

### 需要帮助？

请前往 [OAKChina 官网](https://www.oakchina.cn/) 获取技术支持或解答您的任何疑问。
