此页面由 AI 自动翻译。查看英文原版
DepthAI
  • DepthAI 组件
    • AprilTags
    • 基准测试
    • 相机
    • 校准
    • 深度
    • 检测网络
    • 事件
    • 特征跟踪器
    • 网关
    • 主机节点
    • 图像对齐
    • 图像处理
    • IMU
    • 杂项
    • 模型库
    • 神经深度
    • 神经网络
    • 对象跟踪器
    • 点云
    • 记录回放
    • RGBD
    • 脚本
    • 空间检测网络
    • 空间位置计算器
    • 立体深度
    • 同步
    • ToF
    • 视频编码器
    • 可视化工具
    • VSLAM
    • 扭曲
    • RVC2-特定
  • 高级教程
  • API 参考
  • 工具
软件栈
最后更新

本页目录

  • 源代码
Claude CodeCodexCursor
Luxonis 智能体工具包为你常用的编程智能体加载 Luxonis 上下文与技能,更快地基于 OAK 开发应用。
安装工具包

ToF 所有队列

最后更新
Supported on:RVC2RVC4
此示例同时显示所有主要的 ToF 输出队列,在两个平台上显示 depth、amplitude 和 intensity,以及平台特定的 rawDepth (RVC2) 或 confidence (RVC4) 输出。检测到的平台在启动时打印。
有关完整的输出/架构参考,请参阅 ToF 节点文档。
此示例需要 DepthAI v3 API,请参阅 安装说明。

源代码

Python

Python
GitHub
1#!/usr/bin/env python3
2"""Simple ToF script showing all main ToF output queues.
3
4RVC2 displays: depth, amplitude, intensity, rawDepth.
5RVC4 displays: depth, amplitude, intensity, confidence.
6
7Press 'q' to quit.
8"""
9
10import cv2
11import depthai as dai
12
13FPS = 30.0
14
15
16def normalizeFrame(frame):
17    return cv2.normalize(frame, None, 0, 255, cv2.NORM_MINMAX, cv2.CV_8U)
18
19
20def main():
21    pipeline = dai.Pipeline()
22
23    minDepth = 100.0
24    maxDepth = 7000.0
25
26    profile = dai.ToFConfig.Profile.MID_RANGE
27
28    tof = pipeline.create(dai.node.ToF).build(
29        boardSocket=dai.CameraBoardSocket.AUTO,
30        profile=profile,
31        fps=FPS,
32    )
33
34    with pipeline as p:
35        device = p.getDefaultDevice()
36        isRVC2 = device.getPlatform() == dai.Platform.RVC2
37
38        outputQueues = {
39            "depth": tof.depth.createOutputQueue(maxSize=1, blocking=False),
40            "amplitude": tof.amplitude.createOutputQueue(maxSize=1, blocking=False),
41            "intensity": tof.intensity.createOutputQueue(maxSize=1, blocking=False),
42        }
43        if isRVC2:
44            outputQueues["rawDepth"] = tof.rawDepth.createOutputQueue(maxSize=1, blocking=False)
45        else:
46            outputQueues["confidence"] = tof.confidence.createOutputQueue(maxSize=1, blocking=False)
47
48        platformName = "RVC2" if isRVC2 else "RVC4"
49        print(f"Detected {platformName} - showing queues: {', '.join(outputQueues)}")
50
51        p.start()
52        while p.isRunning():
53            for name, queue in outputQueues.items():
54                frame = queue.tryGet()
55                if frame is None:
56                    continue
57
58                if name in {"depth", "rawDepth"}:
59                    display = dai.utility.colorizeDepthFrame(frame, minDepth, maxDepth, useLog=True).getCvFrame()
60                else:
61                    display = normalizeFrame(frame.getCvFrame())
62                cv2.imshow(name, display)
63
64            if cv2.waitKey(1) == ord("q"):
65                break
66
67
68if __name__ == "__main__":
69    main()

C++

1#include <iostream>
2#include <map>
3#include <opencv2/opencv.hpp>
4#include <string>
5
6#include "depthai/depthai.hpp"
7
8constexpr float FPS = 30.0f;
9cv::Mat normalizeFrame(const cv::Mat& frame) {
10    cv::Mat normalized;
11    cv::normalize(frame, normalized, 0, 255, cv::NORM_MINMAX, CV_8U);
12    return normalized;
13}
14
15int main() {
16    dai::Pipeline pipeline;
17
18    constexpr float minDepth = 100.0f;
19    constexpr float maxDepth = 7000.0f;
20
21    auto profile = dai::ToFConfig::Profile::MID_RANGE;
22
23    auto tof = pipeline.create<dai::node::ToF>()->build(dai::CameraBoardSocket::AUTO, profile, FPS);
24
25    bool isRVC2 = pipeline.getDefaultDevice()->getPlatform() == dai::Platform::RVC2;
26
27    std::map<std::string, std::shared_ptr<dai::MessageQueue>> outputQueues = {
28        {"depth", tof->depth.createOutputQueue(1, false)},
29        {"amplitude", tof->amplitude.createOutputQueue(1, false)},
30        {"intensity", tof->intensity.createOutputQueue(1, false)},
31    };
32    if(isRVC2) {
33        outputQueues["rawDepth"] = tof->rawDepth.createOutputQueue(1, false);
34    } else {
35        outputQueues["confidence"] = tof->confidence.createOutputQueue(1, false);
36    }
37
38    std::cout << "Detected " << (isRVC2 ? "RVC2" : "RVC4") << std::endl;
39
40    pipeline.start();
41    while(pipeline.isRunning()) {
42        for(const auto& [name, queue] : outputQueues) {
43            auto frame = queue->tryGet<dai::ImgFrame>();
44            if(frame == nullptr) {
45                continue;
46            }
47
48            cv::Mat displayFrame;
49
50            if(name == "depth" || name == "rawDepth") {
51                displayFrame = dai::utility::colorizeDepthFrame(*frame, minDepth, maxDepth, cv::COLORMAP_JET, true).getCvFrame();
52            } else {
53                displayFrame = normalizeFrame(frame->getCvFrame());
54            }
55
56            cv::imshow(name, displayFrame);
57        }
58
59        if(cv::waitKey(1) == 'q') {
60            break;
61        }
62    }
63
64    return 0;
65}

需要帮助?

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