DepthAI v2 has been superseded by DepthAI v3. You are viewing legacy documentation.
此页面由 AI 自动翻译。查看英文原版
DepthAI 教程
DepthAI API 参考
最后更新

本页目录

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

延迟测量

最后更新
本示例展示了如何结合使用 ImgFrame 的 .getTimestamp() 函数和 dai.Clock.now() 来测量图像捕获(更准确地说,是 ISP 处理并附加时间戳)到在主机上接收到帧的延迟。如果您想了解更多关于低延迟的信息,请参阅 此处的文档页面。

演示

本示例测量了以 60FPS 运行的 ColorCamera 的 isp 1080P 输出(YUV420 编码帧)的延迟。我们得到了大约 33ms 的延迟,这与 优化延迟文档页面中测量的值相同。
Command Line
1UsbSpeed.SUPER
2Latency: 33.49 ms, Average latency: 33.49 ms, Std: 0.00
3Latency: 34.92 ms, Average latency: 34.21 ms, Std: 0.71
4Latency: 33.23 ms, Average latency: 33.88 ms, Std: 0.74
5Latency: 33.70 ms, Average latency: 33.84 ms, Std: 0.65
6Latency: 33.94 ms, Average latency: 33.86 ms, Std: 0.58
7Latency: 34.18 ms, Average latency: 33.91 ms, Std: 0.54

设置

请运行安装脚本以下载所有必需的依赖项。请注意,此脚本必须在git上下文中运行,因此您必须首先下载depthai-python存储库,然后运行该脚本
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
有关更多信息,请遵循安装指南。

源代码

Python

Python
GitHub
1import depthai as dai
2import numpy as np
3# Create pipeline
4pipeline = dai.Pipeline()
5# This might improve reducing the latency on some systems
6pipeline.setXLinkChunkSize(0)
7
8# Define source and output
9camRgb = pipeline.create(dai.node.ColorCamera)
10camRgb.setFps(60)
11camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
12
13xout = pipeline.create(dai.node.XLinkOut)
14xout.setStreamName("out")
15camRgb.isp.link(xout.input)
16
17# Connect to device and start pipeline
18with dai.Device(pipeline) as device:
19    print(device.getUsbSpeed())
20    q = device.getOutputQueue(name="out")
21    diffs = np.array([])
22    while True:
23        imgFrame = q.get()
24        # Latency in miliseconds 
25        latencyMs = (dai.Clock.now() - imgFrame.getTimestamp()).total_seconds() * 1000
26        diffs = np.append(diffs, latencyMs)
27        print('Latency: {:.2f} ms, Average latency: {:.2f} ms, Std: {:.2f}'.format(latencyMs, np.average(diffs), np.std(diffs)))
28        
29        # Not relevant for this example
30        # cv2.imshow('frame', imgFrame.getCvFrame())

C++

WIP

流水线

需要帮助?

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