# Calibration Flash

This example shows how to flash calibration data from a JSON file to the device's EEPROM. The script automatically backs up the
existing calibration data before flashing.

## Similar samples

 * [Calibration Load](https://docs.luxonis.com/software-v3/depthai/examples/calibration/calibration_load.md)
 * [Calibration Dump](https://docs.luxonis.com/software-v3/depthai/examples/calibration/calibration_dump.md)
 * [Calibration Factory Reset](https://docs.luxonis.com/software-v3/depthai/examples/calibration/calibration_factory_reset.md)

## Demo

Example script output showing successful calibration flashing with automatic backup:

```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
```

## Setup

This example requires the DepthAI v3 API, see [installation instructions](https://docs.luxonis.com/software-v3/depthai.md).

## Source code

```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}")
```

### Need assistance?

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