DepthAI
软件栈

本页目录

  • 源代码

神经辅助立体匹配

Supported on:RVC4
本示例演示了NeuralAssistedStereo节点,它融合了NeuralDepth与传统的StereoDepth
这个示例需要DepthAI v3 API,参见安装说明

源代码

Python

Python
GitHub
1import cv2 as cv
2import depthai as dai
3
4FPS = 20
5
6if __name__ == "__main__":
7    device = dai.Device()
8    pipeline = dai.Pipeline(device)
9    if not device.isNeuralDepthSupported():
10        print("Exiting NeuralAssistedStereo example: device doesn't support NeuralDepth.")
11        exit()
12
13    monoLeft = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B, sensorFps=FPS)
14    monoRight = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C, sensorFps=FPS)
15
16    monoLeftOut = monoLeft.requestFullResolutionOutput()
17    monoRightOut = monoRight.requestFullResolutionOutput()
18
19    neuralAssistedStereo = pipeline.create(dai.node.NeuralAssistedStereo).build(monoLeftOut, monoRightOut, neuralModel=dai.DeviceModelZoo.NEURAL_DEPTH_NANO)
20
21    depthQueue = neuralAssistedStereo.depth.createOutputQueue()
22
23    with pipeline:
24        pipeline.start()
25        while pipeline.isRunning():
26            depth = depthQueue.get()
27            cv.imshow("Depth", dai.utility.colorizeDepthFrame(depth, 500, 12000, cv.COLORMAP_TURBO, useLog=True).getCvFrame())
28
29            key = cv.waitKey(1)
30            if key == ord('q'):
31                quit()

C++

1#include <depthai/depthai.hpp>
2#include <depthai/device/Device.hpp>
3#include <depthai/pipeline/node/Camera.hpp>
4#include <depthai/pipeline/node/NeuralAssistedStereo.hpp>
5#include <iostream>
6#include <opencv2/opencv.hpp>
7
8constexpr float FPS = 20.0f;
9int main() {
10    // 1. Create device and pipeline
11    auto device = std::make_shared<dai::Device>();
12    dai::Pipeline pipeline(device);
13    if(!device->isNeuralDepthSupported()) {
14        std::cout << "Exiting NeuralAssistedStereo example: device doesn't support NeuralDepth.\n";
15        return 0;
16    }
17
18    // 2. Define nodes
19    auto monoLeft = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_B, std::nullopt, FPS);
20    auto monoRight = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_C, std::nullopt, FPS);
21    auto monoRightOut = monoRight->requestFullResolutionOutput();
22    auto monoLeftOut = monoLeft->requestFullResolutionOutput();
23
24    auto neuralAssistedStereo = pipeline.create<dai::node::NeuralAssistedStereo>()->build(*monoLeftOut, *monoRightOut, dai::DeviceModelZoo::NEURAL_DEPTH_NANO);
25
26    // 6. Get output queue
27    auto depthQueue = neuralAssistedStereo->depth.createOutputQueue();
28
29    pipeline.start();
30    while(pipeline.isRunning()) {
31        auto depthPacket = depthQueue->get<dai::ImgFrame>();
32        cv::imshow("Depth", dai::utility::colorizeDepthFrame(*depthPacket, 500.0f, 12000.0f, cv::COLORMAP_TURBO, true).getCvFrame());
33        int key = cv::waitKey(1);
34        if(key == 'q') {
35            break;
36        }
37    }
38    return 0;
39}

需要帮助?

请前往 OAKChina 官网 获取技术支持或解答您的任何疑问。