DepthAI Tutorials
DepthAI API References

ON THIS PAGE

  • Latency measurement
  • Demo
  • Setup
  • Source code
  • Pipeline

Latency measurement

This example shows how to ImgFrame's .getTimestamp() function in combination with dai.Clock.now() to measure the latency since image was captured (more accurately since it was processed by ISP and timestamp was attached to it) until the frame was received on the host computer.If you would like to learn more about low-latency, see the documentation page here.

Demo

This example measures latency of isp 1080P output (YUV420 encoded frame) from ColorCamera running at 60FPS. We get about 33ms, which is what was measured in optimizing latency docs page as well.
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

Setup

Please run the install script to download all required dependencies. Please note that this script must be ran from git context, so you have to download the depthai-python repository first and then run the script
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
For additional information, please follow the installation guide.

Source code

Python
C++

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())

Pipeline

Need assistance?

Head over to Discussion Forum for technical support or any other questions you might have.