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 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 Low Latency docs page as well.
UsbSpeed.SUPER
Latency: 33.49 ms, Average latency: 33.49 ms, Std: 0.00
Latency: 34.92 ms, Average latency: 34.21 ms, Std: 0.71
Latency: 33.23 ms, Average latency: 33.88 ms, Std: 0.74
Latency: 33.70 ms, Average latency: 33.84 ms, Std: 0.65
Latency: 33.94 ms, Average latency: 33.86 ms, Std: 0.58
Latency: 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
git clone https://github.com/luxonis/depthai-python.git
cd depthai-python/examples
python3 install_requirements.py
For additional information, please follow installation guide
Source code¶
Also available on GitHub
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import depthai as dai
import numpy as np
# Create pipeline
pipeline = dai.Pipeline()
# This might improve reducing the latency on some systems
pipeline.setXLinkChunkSize(0)
# Define source and output
camRgb = pipeline.create(dai.node.ColorCamera)
camRgb.setFps(60)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
xout = pipeline.create(dai.node.XLinkOut)
xout.setStreamName("out")
camRgb.isp.link(xout.input)
# Connect to device and start pipeline
with dai.Device(pipeline) as device:
print(device.getUsbSpeed())
q = device.getOutputQueue(name="out")
diffs = np.array([])
while True:
imgFrame = q.get()
# Latency in miliseconds
latencyMs = (dai.Clock.now() - imgFrame.getTimestamp()).total_seconds() * 1000
diffs = np.append(diffs, latencyMs)
print('Latency: {:.2f} ms, Average latency: {:.2f} ms, Std: {:.2f}'.format(latencyMs, np.average(diffs), np.std(diffs)))
# Not relevant for this example
# cv2.imshow('frame', imgFrame.getCvFrame())
|
(Work in progress)