Calibration Flash

This example shows how to flash calibration data of version 6 (gen2 calibration data) to the device.

Similar samples:

Demo

Example script output

~/depthai-python/examples$ python3 Calibration/calibration_flash.py
Calibration Data on the device is backed up at:
/home/erik/Luxonis/depthai-python/examples/Calibration/depthai_calib_backup.json
Calibration Flash Successful

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

git clone https://github.com/luxonis/depthai-python.git
cd depthai-python/examples
python3 install_requirements.py

For additional information, please follow installation guide

Source code

Also available on GitHub

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3

from pathlib import Path
import cv2
import depthai as dai
import argparse

calibJsonFile = str((Path(__file__).parent / Path('../models/depthai_calib.json')).resolve().absolute())
calibBackUpFile = str((Path(__file__).parent / Path('depthai_calib_backup.json')).resolve().absolute())

parser = argparse.ArgumentParser()
parser.add_argument('calibJsonFile', nargs='?', help="Path to V6 calibration file in json", default=calibJsonFile)
args = parser.parse_args()

# Connect device
with dai.Device() as device:

    deviceCalib = device.readCalibration()
    deviceCalib.eepromToJsonFile(calibBackUpFile)
    print("Calibration Data on the device is backed up at:")
    print(calibBackUpFile)
    calibData = dai.CalibrationHandler(args.calibJsonFile)

    status = device.flashCalibration(calibData)
    if status:
        print('Calibration Flash Successful')
    else:
        print('Calibration Flash Failed!!!')

Also available on GitHub

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <cstdio>
#include <iostream>
#include <string>

// Includes common necessary includes for development using depthai library
#include "depthai/depthai.hpp"

int main(int argc, char** argv) {
    std::string calibJsonFile(CALIB_PATH);
    std::string calibBackUpFile("depthai_calib_backup.json");
    if(argc > 1) {
        calibJsonFile = std::string(argv[1]);
    }

    // Connect device
    dai::Device device;

    dai::CalibrationHandler deviceCalib = device.readCalibration();
    deviceCalib.eepromToJsonFile(calibBackUpFile);
    std::cout << "Calibration Data on the device is backed up at:" << calibBackUpFile << std::endl;
    dai::CalibrationHandler calibData(calibJsonFile);

    if(device.flashCalibration(calibData)) {
        std::cout << "Calibration Flash Successful" << std::endl;
    } else {
        std::cout << "Calibration Flash Failed!!!" << std::endl;
    }

    return 0;
}

Got questions?

We’re always happy to help with code or other questions you might have.