DepthAI v2 has been superseded by DepthAI v3. You are viewing legacy documentation.
DepthAI Tutorials
DepthAI API References

ON THIS PAGE

  • Setup
  • Source code
  • Pipeline

Calibration Load

This example shows how to load and use calibration data of version6 (gen2 calibration data) in a pipeline.

Similar samples:

Setup

Please run the install script to download all required dependencies. Please note that this script must be ran from git context, so you have to download the depthai-python repository first and then run the script
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
For additional information, please follow the installation guide.

Source code

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}

Pipeline

Need assistance?

Head over to Discussion Forum for technical support or any other questions you might have.