# 校准加载

本示例展示了如何在管线中从 JSON 文件加载并使用校准数据，以生成深度帧。

## 类似示例

 * [校准闪存](https://docs.luxonis.com/software-v3/depthai/examples/calibration/calibration_flash.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)

## 演示

示例脚本输出显示了深度可视化窗口。脚本从 JSON 文件加载校准数据，并用其配置立体深度管线。

```bash
~/depthai-core/examples/python/calibration$ python3 calibration_load.py path/to/calibration.json
# 深度窗口打开，显示立体深度输出
# 按 'q' 键退出
```

## 设置

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

## 源码

```python
#!/usr/bin/env python3
import cv2
import depthai as dai
import argparse
import cv2

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

calibData = dai.CalibrationHandler(args.calibJsonFile)

with dai.Pipeline() as pipeline:
    pipeline.setCalibrationData(calibData)
    # Define sources and output
    monoLeft = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
    monoRight = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C)
    resolution = (640, 480)
    stereo = pipeline.create(dai.node.StereoDepth).build(
        monoLeft.requestOutput(resolution), monoRight.requestOutput(resolution)
    )
    depthQueue = stereo.depth.createOutputQueue()
    pipeline.start()
    while True:
        # blocking call, will wait until a new data has arrived
        inDepth = depthQueue.get()
        frame = inDepth.getFrame()
        # frame is ready to be shown
        cv2.imshow("depth", frame)
        if cv2.waitKey(1) == ord("q"):
            break
```

### 需要帮助？

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