Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import depthai as dai
  2.  
  3. fps = 30
  4. pipeline = dai.Pipeline()
  5.  
  6. # Color camera
  7. colorCam = pipeline.createColorCamera()
  8. colorCam.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
  9. colorCam.setFps(fps)
  10. colorCam.setBoardSocket(dai.CameraBoardSocket.RGB)
  11. colorCam.setInterleaved(False)
  12. colorCam.setNumFramesPool(15,15,1,1,1)
  13.  
  14. # Script node
  15. io_node = pipeline.create(dai.node.Script)
  16. script = """
  17. import time
  18. preSeqNum = 0
  19. while True:
  20.    cf = node.io['c'].get()
  21.    seqNum = cf.getSequenceNum()
  22.    if seqNum - preSeqNum > 1:
  23.        node.warn(f"Drop {seqNum - preSeqNum} frames at {seqNum}")
  24.    if seqNum % 10 == 0:
  25.        node.io['color'].send(cf)
  26.    preSeqNum = seqNum
  27. """
  28. io_node.setScript(script)
  29. io_node.inputs['c'].setQueueSize(5)
  30. io_node.inputs['c'].setBlocking(True)
  31.  
  32. # Linking
  33. xout_color = pipeline.createXLinkOut()
  34. xout_color.setStreamName("color")
  35.  
  36. xout_color_stream = pipeline.createXLinkOut()
  37. xout_color_stream.setStreamName("color_stream")
  38. xout_color_stream.input.setBlocking(False)
  39. xout_color_stream.input.setQueueSize(5)
  40.  
  41. colorCam.isp.link(io_node.inputs['c'])
  42. colorCam.isp.link(xout_color_stream.input)
  43. io_node.outputs["color"].link(xout_color.input)
  44.  
  45. with dai.Device(pipeline) as device:
  46.     q_color = device.getOutputQueue("color")
  47.     q_color_stream = device.getOutputQueue("color_stream", maxSize=30, blocking=False)
  48.     print("Started")
  49.     while True:
  50.         color_frame = q_color.get()
  51.         print(f"Received sequence number: {color_frame.getSequenceNum()}")