# 校准烧录

该示例展示了如何将第6版校准数据（gen2校准数据）烧录到设备上。

## 类似示例：

 * [校准烧录 v5](https://docs.luxonis.com/software/depthai/examples/calibration_flash_v5.md)
 * [校准读取器](https://docs.luxonis.com/software/depthai/examples/calibration_reader.md)
 * [校准加载](https://docs.luxonis.com/software/depthai/examples/calibration_load.md)

## Demo

示例脚本输出：

```bash
~/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
    # 校准烧录成功
```

## 设置

请运行[安装脚本](https://github.com/luxonis/depthai-python/blob/main/examples/install_requirements.py)以下载所有必需的依赖项。请注意，此脚本必须在 git
上下文中运行，因此您需要先下载 [depthai-python](https://github.com/luxonis/depthai-python) 仓库，然后运行该脚本。

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

更多信息，请参考[安装指南](https://docs.luxonis.com/software/depthai/manual-install.md)。

## 源代码

#### Python

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

from pathlib import Path
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 calibration file in json", default=calibJsonFile)
args = parser.parse_args()

# Connect device
with dai.Device(dai.OpenVINO.VERSION_UNIVERSAL, dai.UsbSpeed.HIGH) 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)

    try:
        device.flashCalibration2(calibData)
        print('Successfully flashed calibration')
    except Exception as ex:
        print(f'Failed flashing calibration: {ex}')
```

#### 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 calibJsonFile(CALIB_PATH);
    std::string calibBackUpFile("depthai_calib_backup.json");
    if(argc > 1) {
        calibJsonFile = std::string(argv[1]);
    }

    // Connect device
    dai::Device device(dai::OpenVINO::VERSION_UNIVERSAL, dai::UsbSpeed::HIGH);

    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);

    try {
        device.flashCalibration2(calibData);
        std::cout << "Successfully flashed calibration" << std::endl;
    } catch(const std::exception& ex) {
        std::cout << "Failed flashing calibration: " << ex.what() << std::endl;
    }

    return 0;
}
```

### 需要帮助？

请前往 [OAKChina 官网](https://www.oakchina.cn/) 获取技术支持或解答您的任何疑问。
