Guest User

Untitled

a guest
Jul 31st, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import depthai as dai
  4. import av
  5. import cv2
  6. # Create pipeline
  7. pipeline = dai.Pipeline()
  8.  
  9. camRgb = pipeline.create(dai.node.ColorCamera)
  10. camRgb.setBoardSocket(dai.CameraBoardSocket.RGB)
  11. camRgb.setFps(30)
  12. camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
  13.  
  14. def create_encoder(name):
  15.     videoEnc = pipeline.create(dai.node.VideoEncoder)
  16.     videoEnc.setDefaultProfilePreset(camRgb.getFps(), dai.VideoEncoderProperties.Profile.H264_MAIN)
  17.     camRgb.video.link(videoEnc.input)
  18.  
  19.     xout = pipeline.create(dai.node.XLinkOut)
  20.     xout.setStreamName(name)
  21.     videoEnc.bitstream.link(xout.input)
  22.  
  23. create_encoder("1")
  24. create_encoder("2")
  25. create_encoder("3")
  26. create_encoder("4")
  27.  
  28. from depthai_sdk.fps import FPSHandler
  29. fps = FPSHandler()
  30.  
  31. with dai.Device(pipeline) as device:
  32.     qs = [device.getOutputQueue(name, maxSize=30, blocking=True) for name in ["1", "2", "3", "4"]]
  33.     codec = av.CodecContext.create("h264", "r")
  34.     stop = False
  35.     while not stop:
  36.         for i, q in enumerate(qs):
  37.             data = q.get().getData()  # Blocking call, will wait until new data has arrived
  38.  
  39.             if i == 0:
  40.                 fps.nextIter()
  41.                 print(fps.fps())
  42.                 packets = codec.parse(data)
  43.  
  44.                 for packet in packets:
  45.                     frames = codec.decode(packet)
  46.                     if frames:
  47.                         frame = frames[0].to_ndarray(format='bgr24')
  48.                         cv2.imshow('frame', frame)
  49.  
  50.                 if cv2.waitKey(1) == ord('q'):
  51.                     stop = True
  52.  
Advertisement
Add Comment
Please, Sign In to add comment