# GPUStereo

This example demonstrates the [GPUStereo](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/gpu_stereo.md)
node on RVC4. It checks device.isGpuStereoSupported(), feeds full-resolution stereo camera outputs into the node, and visualizes
the disparity stream.

This example requires the DepthAI v3 API, see [installation instructions](https://docs.luxonis.com/software-v3/depthai.md).

## What it shows

 * Runtime capability check with device.isGpuStereoSupported()
 * Full-resolution Camera outputs linked into GPUStereo
 * initialConfig.setConfidenceThreshold(25) startup configuration
 * Disparity visualization from the disparity output queue

## Source code

#### Python

```python
#!/usr/bin/env python3
import cv2
import depthai as dai
import numpy as np

device = dai.Device()
if not device.isGpuStereoSupported():
    print("Exiting GPUStereo example: GPUStereo is not supported on this device.")
    raise SystemExit(0)

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

    gpu = pipeline.create(dai.node.GPUStereo)
    camLeft.requestFullResolutionOutput().link(gpu.left)
    camRight.requestFullResolutionOutput().link(gpu.right)
    gpu.initialConfig.setConfidenceThreshold(25)

    dispQ = gpu.disparity.createOutputQueue()

    with pipeline:
        pipeline.start()
        while pipeline.isRunning():
            frame = dispQ.get()
            d = frame.getFrame().astype(np.float32)
            d = cv2.normalize(d, None, 0, 255, cv2.NORM_MINMAX).astype(np.uint8)
            cv2.imshow("GPUStereo Disparity", cv2.applyColorMap(d, cv2.COLORMAP_JET))
            if cv2.waitKey(1) == ord("q"):
                break
```

#### C++

```cpp
/**
 * Minimal GPUStereo example — disparity from a stereo camera pair (RVC4 only).
 */
#include <depthai/depthai.hpp>
#include <iostream>
#include <opencv2/opencv.hpp>

int main() {
    std::shared_ptr<dai::Device> device = std::make_shared<dai::Device>();

    if(!device->isGpuStereoSupported()) {
        std::cout << "Exiting GPUStereo example: GPUStereo is not supported on this device.\n";
        return 0;
    }

    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);

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

    pipeline.start();
    while(pipeline.isRunning()) {
        auto frame = dispQ->get<dai::ImgFrame>();
        cv::Mat disp(frame->getHeight(), frame->getWidth(), CV_16UC1, frame->getData().data());
        cv::Mat dispF;
        disp.convertTo(dispF, CV_32F);
        cv::Mat disp8;
        cv::normalize(dispF, disp8, 0, 255, cv::NORM_MINMAX, CV_8U);
        cv::Mat dispColor;
        cv::applyColorMap(disp8, dispColor, cv::COLORMAP_JET);
        cv::imshow("GPUStereo Disparity", dispColor);
        if(cv::waitKey(1) == 'q') break;
    }

    return 0;
}
```

## Similar samples

 * [Stereo Depth](https://docs.luxonis.com/software-v3/depthai/examples/stereo_depth/stereo_depth.md) - Classical stereo depth
   with a larger configuration surface.
 * [Neural Assisted Stereo](https://docs.luxonis.com/software-v3/depthai/examples/stereo_depth/neural_assisted_stereo.md) - Fuse
   neural depth with classical stereo on RVC4.

### Need assistance?

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