Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2023
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1.  
  2.  
  3. import depthai as dai
  4. import numpy as np
  5. # Create pipeline
  6. pipeline = dai.Pipeline()
  7. # This might improve reducing the latency on some systems
  8. pipeline.setXLinkChunkSize(0)
  9.  
  10. # Define source and output
  11. camRgb = pipeline.create(dai.node.ColorCamera)
  12. camRgb.setFps(30)
  13. camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_4_K)
  14.  
  15. videEnc = pipeline.create(dai.node.VideoEncoder)
  16. videEnc.setDefaultProfilePreset(30, dai.VideoEncoderProperties.Profile.MJPEG)
  17. camRgb.video.link(videEnc.input)
  18.  
  19. xout = pipeline.create(dai.node.XLinkOut)
  20. xout.setStreamName("out")
  21. videEnc.bitstream.link(xout.input)
  22.  
  23. # Connect to device and start pipeline
  24. with dai.Device(pipeline) as device:
  25. print(device.getUsbSpeed())
  26. q = device.getOutputQueue(name="out")
  27. diffs = np.array([])
  28. while True:
  29. imgFrame = q.get()
  30. # Latency in miliseconds
  31. latencyMs = (dai.Clock.now() - imgFrame.getTimestamp()).total_seconds() * 1000
  32. diffs = np.append(diffs, latencyMs)
  33. print('Latency: {:.2f} ms, Average latency: {:.2f} ms, Std: {:.2f}'.format(latencyMs, np.average(diffs), np.std(diffs)))
  34.  
  35. # Not relevant for this example
  36. # cv2.imshow('frame', imgFrame.getCvFrame())
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement