Hi,
We have the rgb and mono camera running at the same framerate. Then we still need to sync the rgb and depth timestamps so that they're exactly the same. We use this script:
def create_sequence_number_sync_script(stream1_in: str, stream2_in: str, stream1_out: str) -> str:
return f"""
from math import isclose
stream1_in = node.io['{stream1_in}']
stream2_in = node.io['{stream2_in}']
stream1_out = node.io['{stream1_out}']
frame1 = None
frame2 = None
while True:
if frame1 is None:
frame1 = stream1_in.get()
if frame2 is None:
frame2 = stream2_in.get()
sequence_number1 = frame1.getSequenceNum()
sequence_number2 = frame2.getSequenceNum()
if sequence_number1 == sequence_number2:
timestamp1 = frame1.getTimestamp()
timestamp2 = frame2.getTimestamp()
assert isclose(timestamp1.total_seconds(), timestamp2.total_seconds(), rel_tol=0.001)
frame1.setTimestamp(timestamp2)
stream1_out.send(frame1)
frame1 = None
frame2 = None
elif sequence_number1 < sequence_number2: # if stream1 is behind ...
frame1 = None # ... dismiss stream1 frame
# ... and keep stream2 frame
else: # if stream2 is behind ...
# ... keep stream1 frame
frame2 = None # ... and dismiss stream2 frame
"""
In which stream1
is the rgb stream and stream2
the depth stream. The script replaces frame1
's (rgb) timestamp with frame2
's (depth) timestamp. This works well, except that every once in a while we get an rgb frame with a timestamp just 1 microsecond behind the depth timestamp, where I'd expect that they are exactly the same.
How can we prevent this? Is this due to some rounding error somewhere setting frame1
's timestamp?