DepthAI v2 has been superseded by DepthAI v3. You are viewing legacy documentation.
此页面由 AI 自动翻译。查看英文原版
DepthAI 教程
DepthAI API 参考

本页目录

  • 设置
  • 源代码
  • 管道

校准加载

此示例演示了如何在管道中加载和使用版本 6(gen2 校准数据)的校准数据。

类似示例:

设置

请运行 安装脚本 以下载所有必需的依赖项。请注意,此脚本必须在 git 上下文中运行,因此您必须先下载 depthai-python 存储库,然后运行脚本
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
有关更多信息,请遵循 安装指南

源代码

Python

Python
GitHub
1#!/usr/bin/env python3
2
3from pathlib import Path
4import cv2
5import depthai as dai
6import argparse
7import numpy as np
8import cv2
9
10calibJsonFile = str((Path(__file__).parent / Path('../models/depthai_calib.json')).resolve().absolute())
11
12parser = argparse.ArgumentParser()
13parser.add_argument('calibJsonFile', nargs='?', help="Path to calibration file in json", default=calibJsonFile)
14args = parser.parse_args()
15
16calibData = dai.CalibrationHandler(args.calibJsonFile)
17
18# Create pipeline
19pipeline = dai.Pipeline()
20pipeline.setCalibrationData(calibData)
21
22# Define sources and output
23monoLeft = pipeline.create(dai.node.MonoCamera)
24monoRight = pipeline.create(dai.node.MonoCamera)
25stereo = pipeline.create(dai.node.StereoDepth)
26xoutDepth = pipeline.create(dai.node.XLinkOut)
27xoutDepth.setStreamName("depth")
28
29# MonoCamera
30monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
31monoLeft.setCamera("left")
32# monoLeft.setFps(5.0)
33monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
34monoRight.setCamera("right")
35# monoRight.setFps(5.0)
36
37# Linking
38monoLeft.out.link(stereo.left)
39monoRight.out.link(stereo.right)
40stereo.depth.link(xoutDepth.input)
41
42# Connect to device and start pipeline
43with dai.Device(pipeline) as device:
44
45    depthQueue = device.getOutputQueue(name="depth", maxSize=4, blocking=False)
46
47    while True:
48        # blocking call, will wait until a new data has arrived
49        inDepth = depthQueue.get()
50        frame = inDepth.getFrame()
51
52        # frame is ready to be shown
53        cv2.imshow("depth", frame)
54
55        if cv2.waitKey(1) == ord('q'):
56            break

C++

1#include <cstdio>
2#include <iostream>
3#include <string>
4
5// Includes common necessary includes for development using depthai library
6#include "depthai-shared/common/CameraBoardSocket.hpp"
7#include "depthai-shared/common/EepromData.hpp"
8#include "depthai/depthai.hpp"
9
10int main(int argc, char** argv) {
11    std::string calibJsonFile(CALIB_PATH);
12    if(argc > 1) {
13        calibJsonFile = std::string(argv[1]);
14    }
15    dai::CalibrationHandler calibData(calibJsonFile);
16
17    // Create pipeline
18    dai::Pipeline pipeline;
19    pipeline.setCalibrationData(calibData);
20
21    // Define sources and output
22    auto monoLeft = pipeline.create<dai::node::MonoCamera>();
23    auto monoRight = pipeline.create<dai::node::MonoCamera>();
24    auto stereo = pipeline.create<dai::node::StereoDepth>();
25    auto xoutDepth = pipeline.create<dai::node::XLinkOut>();
26    xoutDepth->setStreamName("depth");
27
28    // MonoCamera
29    monoLeft->setResolution(dai::MonoCameraProperties::SensorResolution::THE_720_P);
30    monoLeft->setCamera("left");
31    // monoLeft->setFps(5.0);
32    monoRight->setResolution(dai::MonoCameraProperties::SensorResolution::THE_720_P);
33    monoRight->setCamera("right");
34    // monoRight->setFps(5.0);
35
36    // Linking
37    monoLeft->out.link(stereo->left);
38    monoRight->out.link(stereo->right);
39    stereo->depth.link(xoutDepth->input);
40
41    // Connect to device and start pipeline
42    dai::Device device(pipeline);
43
44    auto depthQueue = device.getOutputQueue("depth", 4, false);
45
46    while(true) {
47        // blocking call, will wait until a new data has arrived
48        auto inDepth = depthQueue->get<dai::ImgFrame>();
49        cv::Mat frame = cv::Mat(inDepth->getHeight(), inDepth->getWidth(), CV_16UC1, inDepth->getData().data());
50
51        // frame is ready to be shown
52        cv::imshow("depth", frame);
53
54        int key = cv::waitKey(1);
55        if(key == 'q') {
56            return 0;
57        }
58    }
59    return 0;
60}

管道

需要帮助?

请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。