# GPUStereo

GPUStereo computes disparity and depth from a synchronized stereo pair on the RVC4 GPU. It accepts either live camera outputs or
already-rectified frames, with built-in rectification enabled by default.

> GPUStereo is only supported on
> **RVC4**
> devices and was added in
> **DepthAI 3.7.1**
> . You can guard runtime code with
> `device.isGpuStereoSupported()`
> .

## How to place it

GPUStereo is a device node, so create the pipeline with a dai.Device instance.

#### Python

```python
import depthai as dai

device = dai.Device()
if not device.isGpuStereoSupported():
    raise RuntimeError("GPUStereo is not supported on this device.")

with dai.Pipeline(device) as pipeline:
    cam_left = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
    cam_right = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C)

    gpu = pipeline.create(dai.node.GPUStereo)
    cam_left.requestFullResolutionOutput().link(gpu.left)
    cam_right.requestFullResolutionOutput().link(gpu.right)
```

#### C++

```cpp
#include <depthai/depthai.hpp>

auto device = std::make_shared<dai::Device>();
if(!device->isGpuStereoSupported()) {
    throw std::runtime_error("GPUStereo is not supported on this device.");
}

dai::Pipeline pipeline(device);
auto camLeft = pipeline.create<dai::node::Camera>();
auto camRight = pipeline.create<dai::node::Camera>();
camLeft->build(dai::CameraBoardSocket::CAM_B);
camRight->build(dai::CameraBoardSocket::CAM_C);

auto gpu = pipeline.create<dai::node::GPUStereo>();
camLeft->requestFullResolutionOutput()->link(gpu->left);
camRight->requestFullResolutionOutput()->link(gpu->right);
```

## Inputs and Outputs

 * disparity outputs RAW16 disparity data.
 * depth outputs RAW16 depth data in the configured depth unit, millimeters by default.
 * confidenceMap outputs an 8-bit confidence map where lower values indicate lower-confidence matches.

## Usage

The public startup configuration for GPUStereo is intentionally small in 3.7.1. initialConfig exposes confidenceThreshold, and you
can disable internal rectification when providing already-rectified inputs.

#### Python

```python
import depthai as dai

device = dai.Device()

with dai.Pipeline(device) as pipeline:
    cam_left = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
    cam_right = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C)

    gpu = pipeline.create(dai.node.GPUStereo)
    cam_left.requestFullResolutionOutput().link(gpu.left)
    cam_right.requestFullResolutionOutput().link(gpu.right)

    gpu.initialConfig.setConfidenceThreshold(25)
    # If your inputs are already rectified, disable internal rectification.
    # gpu.setRectification(False)

    disp_q = gpu.disparity.createOutputQueue()
    depth_q = gpu.depth.createOutputQueue()
```

#### C++

```cpp
#include <depthai/depthai.hpp>

auto device = std::make_shared<dai::Device>();
dai::Pipeline pipeline(device);

auto camLeft = pipeline.create<dai::node::Camera>();
auto camRight = pipeline.create<dai::node::Camera>();
camLeft->build(dai::CameraBoardSocket::CAM_B);
camRight->build(dai::CameraBoardSocket::CAM_C);

auto gpu = pipeline.create<dai::node::GPUStereo>();
camLeft->requestFullResolutionOutput()->link(gpu->left);
camRight->requestFullResolutionOutput()->link(gpu->right);

gpu->initialConfig->setConfidenceThreshold(25);
// If your inputs are already rectified, disable internal rectification.
// gpu->setRectification(false);

auto dispQ = gpu->disparity.createOutputQueue();
auto depthQ = gpu->depth.createOutputQueue();
```

## Reference

### dai::node::GPUStereo

Kind: class

GPU-accelerated stereo depth node for RVC4.

Computes disparity and depth maps from a synchronized stereo camera pair using OpenCL on the Adreno GPU. Supports both rectified
and unrectified inputs (controlled via setRectification ).

#### Subnode < Sync > sync

Kind: variable

#### Subnode < MessageDemux > messageDemux

Kind: variable

#### std::unique_ptr< Subnode < Rectification > > rectification

Kind: variable

#### Input & left

Kind: variable

#### Input & right

Kind: variable

#### Input leftInternal

Kind: variable

#### Input rightInternal

Kind: variable

#### Output disparity

Kind: variable

Outputs ImgFrame message that carries RAW16 encoded disparity data.

#### Output depth

Kind: variable

Outputs ImgFrame message that carries RAW16 encoded (0..65535) depth data in depth units (millimeter by default). Non-determined /
invalid depth values are set to 0

#### Output confidenceMap

Kind: variable

Outputs ImgFrame message that carries RAW8 confidence map. Lower values mean lower confidence of the calculated disparity value.
Note: postprocessing steps like LR-check/median filter are not applied to confidence map.

#### std::shared_ptr< GPUStereoConfig > initialConfig

Kind: variable

Initial config to use for GPUStereo . Use this to configure startup parameters before the pipeline starts. Note: Only

#### GPUStereo()

Kind: function

#### std::shared_ptr< GPUStereo > build(Output & left, Output & right)

Kind: function

Build the node by linking left and right camera outputs.

#### GPUStereo & setRectification(bool enable)

Kind: function

Enable or disable built-in stereo rectification.

When enabled, the node rectifies the input images internally using calibration data. When disabled, inputs are expected to be
already rectified.

#### void buildInternal()

Kind: function

Function called from within the

## Examples of functionality

 * [GPUStereo](https://docs.luxonis.com/software-v3/depthai/examples/stereo_depth/gpu_stereo.md) - Run GPU-accelerated stereo on
   RVC4 and visualize the disparity output.

### Need assistance?

Head over to [Discussion Forum](https://discuss.luxonis.com/) for technical support or any other questions you might have.
