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

本页目录

  • 演示
  • 设置
  • 源代码
  • Pipeline

延迟测量

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

演示

此示例测量了 ColorCamera 以 60FPS 运行的 isp 1080P 输出(YUV420 编码帧)的延迟。我们获得了 大约 33 毫秒,这与 优化延迟 文档页面中的测量值相同。
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++

开发中

Pipeline

需要帮助?

请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。