此页面由 AI 自动翻译。查看英文原版
最后更新

本页目录

  • 启用自动校准的三种方式
  • 通过全局变量进行自动校准
  • 行为说明
  • ON_START 过程
  • CONTINUOUS 过程
  • 通过管道设置器进行自动校准
  • 管道中的 AutoCalibration 主机节点
  • 示例
  • 配置参数
  • 节点输出(结果)
  • 可用性和推出状态
  • 反馈
  • 参考
Claude CodeCodexCursor
Luxonis 智能体工具包为你常用的编程智能体加载 Luxonis 上下文与技能,更快地基于 OAK 开发应用。
安装工具包

自动校准

最后更新
Supported on:RVC2RVC4
AutoCalibration 是一个主机节点,它在管道中运行自动立体校准工作流,并在运行时提供校准质量结果。区分两个层面很重要:
  • AutoCalibration 是您添加到管道中的主机节点。
  • 在内部,它在后台控制并使用 DynamicCalibration。
  • DEPTHAI_AUTOCALIBRATION 是自动校准的全局部署开关。

启用自动校准的三种方式

根据您需要的控制程度进行选择:
  • 全局变量 (DEPTHAI_AUTOCALIBRATION) 最适合已部署的管道,您希望在不更改代码的情况下启用自动行为。
  • AutoCalibration 主机节点 最适合您希望对模式、重试、验证、刷写和结果处理进行显式管道级控制的情况。
  • 管道设置器 (pipeline.setAutoCalibrationMode(...)) 最适合您希望进行轻量级代码级控制而无需添加 AutoCalibration 主机节点的情况。

通过全局变量进行自动校准

使用以下环境变量之一:
Command Line
1DEPTHAI_AUTOCALIBRATION=ON_START
2DEPTHAI_AUTOCALIBRATION=CONTINUOUS
3DEPTHAI_AUTOCALIBRATION=OFF
这些值在不向应用程序添加节点级 API 处理的情况下运行自动校准。

行为说明

  • 适用于立体 1280x800 和 640x400 管道。
  • 将校准刷写为用户校准。
  • 出厂校准保持不变。
  • 如果您的管道已包含 DynamicCalibration 节点或 AutoCalibration 节点,则不会初始化基于 AutoCalibrationMode 的自动过程。

ON_START 过程

在启动期间运行自动校准,然后继续正常的管道执行。

示例

Command Line
1DEPTHAI_AUTOCALIBRATION=ON_START python3 examples/Stereo/stereo.py
可选的详细日志:
Command Line
1DEPTHAI_LEVEL=info DEPTHAI_AUTOCALIBRATION=ON_START python3 examples/Stereo/stereo.py
如果启动校准验证失败,则不会刷写新的校准。典型的启动时间取决于场景覆盖率和重试次数:
  • 快速路径:约 2.5s。
  • 常见重试路径:约 6s。
  • 最坏情况重试 (maxIterations = 10):最多约 25s。

CONTINUOUS 过程

在运行时持续运行校准,适应不断变化的热/机械条件。

示例

Command Line
1DEPTHAI_AUTOCALIBRATION=CONTINUOUS python3 examples/Stereo/stereo.py
可选的详细日志:
Command Line
1DEPTHAI_LEVEL=info DEPTHAI_AUTOCALIBRATION=CONTINUOUS python3 examples/Stereo/stereo.py
与 ON_START 不同,此模式会增加持续的处理开销。

通过管道设置器进行自动校准

当您希望在代码中进行显式模式控制而无需添加 AutoCalibration 主机节点时,请使用 pipeline.setAutoCalibrationMode(...)。

Python

Python
1pipeline = dai.Pipeline()
2pipeline.setAutoCalibrationMode(dai.Pipeline.AutoCalibrationMode.ON_START)
3# 或者持续运行:
4# pipeline.setAutoCalibrationMode(dai.Pipeline.AutoCalibrationMode.CONTINUOUS)
5
6# 禁用自动校准
7pipeline.setAutoCalibrationMode(dai.Pipeline.AutoCalibrationMode.OFF)

C++

C++
1dai::Pipeline pipeline;
2pipeline.setAutoCalibrationMode(dai::Pipeline::AutoCalibrationMode::ON_START);
3// 或者持续运行:
4// pipeline.setAutoCalibrationMode(dai::Pipeline::AutoCalibrationMode::CONTINUOUS);
5
6// 禁用自动校准
7pipeline.setAutoCalibrationMode(dai::Pipeline::AutoCalibrationMode::OFF);

管道中的 AutoCalibration 主机节点

当您需要显式控制并直接访问运行时输出时,请使用此方法。

示例

以下示例使用 1280x800 立体输入,但相同的 AutoCalibration 工作流也支持 640x400。

Python

Python
1import cv2 as cv
2import numpy as np
3import depthai as dai
4
5# 创建管道
6with dai.Pipeline() as pipeline:
7    device = pipeline.getDefaultDevice()
8    botchCalibration(device)
9
10    camLeft = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
11    camRight = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C)
12    stereo = pipeline.create(dai.node.StereoDepth)
13
14    dcWorker = pipeline.create(dai.node.AutoCalibration).build(camLeft, camRight)
15    dcWorker.initialConfig.maxIterations = 2
16    dcWorker.initialConfig.sleepingTime = 10
17    dcWorker.initialConfig.flashCalibration = False 
18    dcWorker.initialConfig.mode = dai.AutoCalibrationConfig.CONTINUOUS  # ON_START
19    dcWorker.initialConfig.validationSetSize = 5 
20    dcWorker.initialConfig.dataConfidenceThreshold = 0.7
21    workerOutputQueue = dcWorker.output.createOutputQueue()
22
23    videoQueueLeft = camLeft.requestOutput((1280, 800), fps=30)
24    videoQueueRight = camRight.requestOutput((1280, 800), fps=30)
25
26    videoQueueLeft.link(stereo.left)
27    videoQueueRight.link(stereo.right)
28
29    stereoOut = stereo.depth.createOutputQueue()
30    pipeline.start()
31
32    while pipeline.isRunning():
33        workerOutput = workerOutputQueue.tryGet()
34        if workerOutput is not None:
35            if workerOutput.passed:
36                print("Passed")
37                print(f"dataConfidence = {workerOutput.dataConfidence}")
38                print(f"calibrationConfidence = {workerOutput.calibrationConfidence}")
39            else:
40                print("Did not pass")
41
42        depth = stereoOut.get()
43        cv.imshow("Depth", depth)
44
45        if cv.waitKey(1) == ord("q"):
46            break
47        
48    pipeline.stop()

C++

C++
1#include <iostream>
2#include <memory>
3#include <opencv2/opencv.hpp>
4#include <vector>
5
6#include "depthai/depthai.hpp"
7int main() {
8    dai::Pipeline pipeline;
9
10    // 创建设备
11    auto device = pipeline.getDefaultDevice();
12
13    // 节点
14    auto camLeft = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_B);
15    auto camRight = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_C);
16    auto stereo = pipeline.create<dai::node::StereoDepth>();
17
18    // AutoCalibration 节点
19    auto dcWorker = pipeline.create<dai::node::AutoCalibration>();
20    dcWorker->build(camLeft, camRight);
21
22    auto config = dcWorker->initialConfig;
23    config->maxIterations = 2;
24    config->sleepingTime = 10;
25    config->flashCalibration = false;
26    config->mode = dai::AutoCalibrationConfig::CONTINUOUS;
27    config->validationSetSize = 5;
28    config->dataConfidenceThreshold = 0.7;
29
30    // 链接
31    camLeft->requestOutput({1280, 800})->link(stereo->left);
32    camRight->requestOutput({1280, 800})->link(stereo->right);
33
34    // 队列
35    auto workerOutputQueue = dcWorker->output.createOutputQueue();
36    auto stereoOut = stereo->depth.createOutputQueue();
37
38    pipeline.start();
39
40    while(pipeline.isRunning()) {
41        auto workerOutput = workerOutputQueue->tryGet<dai::AutoCalibrationResult>();
42        if(workerOutput != nullptr) {
43            if(workerOutput->passed) {
44                std::cout << "Passed. Confidence: " << workerOutput->dataConfidence << std::endl;
45            } else {
46                std::cout << "Did not pass." << std::endl;
47            }
48        }
49
50        auto depth = stereoOut->get<dai::ImgFrame>();
51        cv::imshow("Depth", depth);
52
53        if(cv::waitKey(1) == 'q') break;
54    }
55
56    return 0;
57}

配置参数

通过 auto_calib.initialConfig 配置行为:
  • mode 选择自动校准过程(ON_START 或 CONTINUOUS)。
  • flashCalibration 如果为 true,则在成功验证后将校准刷写为用户校准。
  • maxIterations 最大校准尝试次数。
  • sleepingTime 校准尝试/迭代之间的延迟。
  • validationSetSize 接受校准前使用的验证样本数量。

节点输出(结果)

该节点提供 AutoCalibrationResult 消息。常见字段:
  • passed 校准/验证是否成功。
  • dataQuality 收集到的校准数据的质量指标。
  • calibrationConfidence 结果校准的置信度分数。

可用性和推出状态

  • DepthAI 3.5.0 通过 DEPTHAI_AUTOCALIBRATION 提供启动自动校准作为可选测试版。
  • 从 DepthAI 3.6 开始,自动校准默认以 ON_START 模式启用。
  • 使用 DEPTHAI_AUTOCALIBRATION=OFF 或 pipeline.setAutoCalibrationMode(...OFF) 禁用它。
安装示例:
Command Line
1python3 -m pip install depthai==3.5.0

反馈

如果您遇到问题或希望改进 API,请通过以下方式报告:

参考

class

dai::node::AutoCalibration

using
variable
std::shared_ptr< AutoCalibrationConfig > initialConfig
variable
Output output
function
std::shared_ptr< AutoCalibration > build(const std::shared_ptr< Camera > & cameraLeft, const std::shared_ptr< Camera > & cameraRight)
function
~AutoCalibration()
function
void run()
function
void setRunOnHost(bool runOnHost)
function
bool runOnHost()
Returns true or false whether the node should be run on host or not.
function
void buildInternal()
Function called from within the create function to build the node. This function is useful for initialization, setting up inputs and outputs = stuff that cannot be perform in the constuctor.
inline function
DeviceNodeCRTP()
inline function
DeviceNodeCRTP(const std::shared_ptr< Device > & device)
inline function
DeviceNodeCRTP(std::unique_ptr< Properties > props)
inline function
DeviceNodeCRTP(std::unique_ptr< Properties > props, bool confMode)
inline function
DeviceNodeCRTP(const std::shared_ptr< Device > & device, std::unique_ptr< Properties > props, bool confMode)

需要帮助?

请访问讨论论坛以获取技术支持或您可能有的任何其他问题。