# 校准烧录

该示例展示了如何将 JSON 文件中的校准数据烧录到设备的 EEPROM。脚本会在烧录前自动备份现有的校准数据。

## 类似示例

 * [校准加载](https://docs.luxonis.com/software-v3/depthai/examples/calibration/calibration_load.md)
 * [校准转储](https://docs.luxonis.com/software-v3/depthai/examples/calibration/calibration_dump.md)
 * [校准恢复出厂设置](https://docs.luxonis.com/software-v3/depthai/examples/calibration/calibration_factory_reset.md)

## 演示

示例脚本输出，展示了成功烧录校准数据并自动备份的过程：

```bash
~/depthai-core/examples/python/calibration$ python3 calibration_flash.py path/to/calibration.json
Calibration Data on the device is backed up at:
/home/user/depthai-core/examples/python/calibration/depthai_calib_backup.json
Successfully flashed calibration
```

## 设置

这个示例需要DepthAI v3 API，参见[安装说明](https://docs.luxonis.com/software-v3/depthai.md)。

## 源代码

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

from pathlib import Path
import depthai as dai
import argparse

calibBackUpFile = str(
    (Path(__file__).parent / Path("depthai_calib_backup.json")).resolve().absolute()
)

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

device = dai.Device(dai.UsbSpeed.HIGH)
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.flashCalibration(calibData)
    print("Successfully flashed calibration")
except Exception as ex:
    print(f"Failed flashing calibration: {ex}")
```

### 需要帮助？

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