Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import depthai as dai
- fps = 30
- pipeline = dai.Pipeline()
- # Color camera
- colorCam = pipeline.createColorCamera()
- colorCam.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
- colorCam.setFps(fps)
- colorCam.setBoardSocket(dai.CameraBoardSocket.RGB)
- colorCam.setInterleaved(False)
- colorCam.setNumFramesPool(15,15,1,1,1)
- # Script node
- io_node = pipeline.create(dai.node.Script)
- script = """
- import time
- preSeqNum = 0
- while True:
- cf = node.io['c'].get()
- seqNum = cf.getSequenceNum()
- if seqNum - preSeqNum > 1:
- node.warn(f"Drop {seqNum - preSeqNum} frames at {seqNum}")
- if seqNum % 10 == 0:
- node.io['color'].send(cf)
- preSeqNum = seqNum
- """
- io_node.setScript(script)
- io_node.inputs['c'].setQueueSize(5)
- io_node.inputs['c'].setBlocking(True)
- # Linking
- xout_color = pipeline.createXLinkOut()
- xout_color.setStreamName("color")
- xout_color_stream = pipeline.createXLinkOut()
- xout_color_stream.setStreamName("color_stream")
- xout_color_stream.input.setBlocking(False)
- xout_color_stream.input.setQueueSize(5)
- colorCam.isp.link(io_node.inputs['c'])
- colorCam.isp.link(xout_color_stream.input)
- io_node.outputs["color"].link(xout_color.input)
- with dai.Device(pipeline) as device:
- q_color = device.getOutputQueue("color")
- q_color_stream = device.getOutputQueue("color_stream", maxSize=30, blocking=False)
- print("Started")
- while True:
- color_frame = q_color.get()
- print(f"Received sequence number: {color_frame.getSequenceNum()}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement