3.7. Calibration Load
此示例显示如何在管道中加载和使用版本6的校准数据(第2代校准数据)。
其他示例:
3.7.1. 设置
请运行 安装依赖脚本 以下载所有必需的依赖项。请注意,此脚本必须在git上下文中运行,因此您必须先下载 depthai-python 存储库,然后再运行该脚本:
git clone https://github.com/luxonis/depthai-python.git
cd depthai-python/examples
python3 install_requirements.py
3.7.2. 源代码
可以在 GitHub 上找到。国内用户也可以在 gitee 上找到。
#!/usr/bin/env python3
from pathlib import Path
import cv2
import depthai as dai
import argparse
import numpy as np
import cv2
calibJsonFile = str((Path(__file__).parent / Path('../models/depthai_calib.json')).resolve().absolute())
parser = argparse.ArgumentParser()
parser.add_argument('calibJsonFile', nargs='?', help="Path to V6 calibration file in json", default=calibJsonFile)
args = parser.parse_args()
calibData = dai.CalibrationHandler(args.calibJsonFile)
# Create pipeline
pipeline = dai.Pipeline()
pipeline.setCalibrationData(calibData)
# Define sources and output
monoLeft = pipeline.create(dai.node.MonoCamera)
monoRight = pipeline.create(dai.node.MonoCamera)
stereo = pipeline.create(dai.node.StereoDepth)
xoutDepth = pipeline.create(dai.node.XLinkOut)
xoutDepth.setStreamName("depth")
# MonoCamera
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT)
# monoLeft.setFps(5.0)
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
monoRight.setBoardSocket(dai.CameraBoardSocket.RIGHT)
# monoRight.setFps(5.0)
# Linking
monoLeft.out.link(stereo.left)
monoRight.out.link(stereo.right)
stereo.depth.link(xoutDepth.input)
# Connect to device and start pipeline
with dai.Device(pipeline) as device:
depthQueue = device.getOutputQueue(name="depth", maxSize=4, blocking=False)
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