# Calibration Flash v5

This example shows how to flash calibration data of version 5 (gen1 calibration data) to the device.

### Similar samples:

 * [Calibration Flash](https://docs.luxonis.com/software/depthai/examples/calibration_flash.md)
 * [Calibration Reader](https://docs.luxonis.com/software/depthai/examples/calibration_reader.md)
 * [Calibration Load](https://docs.luxonis.com/software/depthai/examples/calibration_load.md)

## Setup

Please run the [install script](https://github.com/luxonis/depthai-python/blob/main/examples/install_requirements.py) to download
all required dependencies. Please note that this script must be ran from git context, so you have to download the
[depthai-python](https://github.com/luxonis/depthai-python) repository first and then run the script

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

For additional information, please follow the [installation guide](https://docs.luxonis.com/software/depthai/manual-install.md).

## Source code

#### Python

```python
#!/usr/bin/env python3

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

boardConfigFile = str((Path(__file__).parent / Path('../models/BW1098OBC.json')).resolve().absolute())
calibBinaryFile = str((Path(__file__).parent / Path('../models/depthai_v5.calib')).resolve().absolute())
calibBackUpFile = str((Path(__file__).parent / Path('depthai_calib_backup.json')).resolve().absolute())

parser = argparse.ArgumentParser()
parser.add_argument('boardConfigFile', nargs='?', help="Path to board config file", default=boardConfigFile)
parser.add_argument('calibBinaryFile', nargs='?', help="Path to version 5 .calib file", default=calibBinaryFile)
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.calibBinaryFile, args.boardConfigFile)

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

#### C++

```cpp
#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 calibBinaryFile(CALIB_PATH), boardConfigFile(BOARD_PATH);
    std::string calibBackUpFile("depthai_calib_backup.json");
    if(argc > 2) {
        calibBinaryFile = std::string(argv[1]);
        boardConfigFile = std::string(argv[2]);
    }

    // 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(calibBinaryFile, boardConfigFile);

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

    return 0;
}
```

### Need assistance?

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