Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] .setTimestamp() inside Script node only sets the deviceTimestamp #1072

Open
jakaskerl opened this issue Sep 16, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@jakaskerl
Copy link
Contributor

jakaskerl commented Sep 16, 2024

Setting timestamp via ImgFrame.setTimestamp() only sets device timestamp. When read on host side, via getTimestamp() the value is unaffected. getTimestampDevice() works as expected.

Repro code:



import depthai as dai
import cv2
from math import isclose

# Setup the pipeline
pipeline = dai.Pipeline()

# Create nodes for RGB and mono streams
rgbCamera = pipeline.create(dai.node.ColorCamera)
monoCamera = pipeline.create(dai.node.MonoCamera)

# Set camera properties
rgbCamera.setBoardSocket(dai.CameraBoardSocket.RGB)
monoCamera.setBoardSocket(dai.CameraBoardSocket.LEFT)
rgbCamera.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
monoCamera.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)


# Create a script node
script = pipeline.create(dai.node.Script)
script.setScript("""
import time
stream1_in = node.io['rgb']
stream2_in = node.io['mono']
stream1_out = node.io['synced_rgb']
stream2_out = node.io['synced_mono']

while True:
    frame1 = stream1_in.get()
    frame2 = stream2_in.get()

    timestamp1 = frame1.getTimestamp()
    timestamp2 = frame2.getTimestamp()
    node.warn(f"RGB Frame Timestamp: {timestamp1}")
    node.warn(f"Mono Frame Timestamp: {timestamp2}")

    # Set the RGB frame's timestamp to match the mono frame's timestamp
    frame1.setTimestamp(timestamp2)
    frame1.setSequenceNum(frame2.getSequenceNum())
                 
    node.warn(f"RGB Frame Timestamp after sync: {frame1.getTimestamp()}")
    node.warn(f"Mono Frame Timestamp after sync: {frame2.getTimestamp()}")
                 
    # Send the synchronized frames to the output
    stream1_out.send(frame1)
    stream2_out.send(frame2)
                 
    
""")

# Link the outputs to the script node
rgbCamera.video.link(script.inputs['rgb'])
monoCamera.out.link(script.inputs['mono'])

# Create XLinkOut nodes to output the synchronized streams
xoutSyncedRgb = pipeline.create(dai.node.XLinkOut)
xoutSyncedRgb.setStreamName("synced_rgb")
script.outputs['synced_rgb'].link(xoutSyncedRgb.input)

xoutSyncedmono = pipeline.create(dai.node.XLinkOut)
xoutSyncedmono.setStreamName("synced_mono")
script.outputs['synced_mono'].link(xoutSyncedmono.input)

# Connect to device and start pipeline
with dai.Device(pipeline) as device:
    rgbQueue = device.getOutputQueue(name="synced_rgb", maxSize=8, blocking=False)
    monoQueue = device.getOutputQueue(name="synced_mono", maxSize=8, blocking=False)

    while True:
        syncedRgbFrame = rgbQueue.get()
        syncedMonoFrame = monoQueue.get()
    
        # Get timestamps after synchronization
        rgbTimestamp = syncedRgbFrame.getTimestamp().total_seconds()
        monoTimestamp = syncedMonoFrame.getTimestamp().total_seconds()

        # Print the synchronized timestamps
        print(f"Synced RGB Frame Timestamp: {rgbTimestamp}")
        print(f"Synced mono Frame Timestamp: {monoTimestamp}")

        print(f"RGB Frame Device timestamp: {syncedRgbFrame.getTimestampDevice().total_seconds()}")
        print(f"Mono Frame Device timestamp: {syncedMonoFrame.getTimestampDevice().total_seconds()}")

        # Check if the timestamps differ too much
        if not isclose(rgbTimestamp, monoTimestamp, abs_tol=0.000001):
            raise SystemExit(f"Warning: Timestamps differ more than expected: RGB {rgbTimestamp}, mono {monoTimestamp}")

        # Break the loop if 'q' is pressed
        if cv2.waitKey(1) == ord('q'):
            break
@jakaskerl jakaskerl added the bug Something isn't working label Sep 16, 2024
@jakaskerl jakaskerl changed the title [BUG] .setTimestamp() inside Script node has unexpected behaviour [BUG] .setTimestamp() inside Script node only sets the deviceTimestamp Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant