Skip to content

Commit

Permalink
CR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Aug 30, 2021
1 parent 71b2415 commit 474a33a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
1 change: 1 addition & 0 deletions tools/convert/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Console app for converting ROS-bag files to various formats (currently supported
|`-r <raw-path>`|convert to RAW, set output path to raw-path||
|`-l <ply-path>`|convert to PLY, set output path to ply-path||
|`-b <bin-path>`|convert to BIN (depth matrix), set output path to bin-path||
|`-T`|convert to text (frame dump) output to standard out||
|`-d`|convert depth frames only||
|`-c`|convert color frames only||

Expand Down
45 changes: 41 additions & 4 deletions unit-tests/syncer/sw.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,37 @@
#
domain = rs.timestamp_domain.hardware_clock # For either depth/color
#
# To be set before init()
# To be set before init() or playback()
#
fps_c = fps_d = 60
w = 640
h = 480
bpp = 2 # bytes
#
# Set by init() or playback() -- don't set these unless you know what you're doing!
#
gap_c = gap_d = 0
pixels = None
device = None
depth_sensor = None
color_sensor = None
depth_profile = None
color_profile = None
syncer = None
playback_status = None


def init():
"""
One of the two initialization functions:
Use init() to initialize a software device that will generate frames (as opposed to playback()
which will initialize a software device for reading from a rosbag and will NOT generate frames).
This should be followed by start() to actually start "streaming".
This sets multiple module variables that are used to generate software frames, and initializes
a syncer automatically.
"""
global gap_c, gap_d
gap_d = 1000 / fps_d
Expand Down Expand Up @@ -79,6 +98,18 @@ def playback_callback( status ):

def playback( filename, use_syncer = True ):
"""
One of the two initialization functions:
Use playback() to initialize a software device for reading from a rosbag file. This device will
NOT generate frames! Only the expect() functions will be available.
If you use this function, it replaces init().
This should be followed by start() to actually start "streaming".
:param filename: The path to the file to open for playback
:param use_syncer: If True, a syncer will be used to attempt frame synchronization -- otherwise
a regular queue will be used
"""
ctx = rs.context()
#
Expand Down Expand Up @@ -145,8 +176,11 @@ def reset():
def generate_depth_frame( frame_number, timestamp ):
"""
"""
global depth_profile, domain, pixels, depth_sensor, w, bpp
global playback_status
if playback_status is not None:
raise RuntimeError( "cannot generate frames when playing back" )
#
global depth_profile, domain, pixels, depth_sensor, w, bpp
depth_frame = rs.software_video_frame()
depth_frame.pixels = pixels
depth_frame.stride = w * bpp
Expand All @@ -162,8 +196,11 @@ def generate_depth_frame( frame_number, timestamp ):
def generate_color_frame( frame_number, timestamp ):
"""
"""
global color_profile, domain, pixels, color_sensor, w, bpp
global playback_status
if playback_status is not None:
raise RuntimeError( "cannot generate frames when playing back" )
#
global color_profile, domain, pixels, color_sensor, w, bpp
color_frame = rs.software_video_frame()
color_frame.pixels = pixels
color_frame.stride = w * bpp
Expand Down Expand Up @@ -195,7 +232,7 @@ def expect( depth_frame = None, color_frame = None, nothing_else = False ):
break
time.sleep( 0.1 )
f = syncer.poll_for_frame()
# NOTE: fs will never be None
# NOTE: f will never be None
if not f:
test.check( depth_frame is None, "expected a depth frame" )
test.check( color_frame is None, "expected a color frame" )
Expand Down
14 changes: 14 additions & 0 deletions unit-tests/syncer/test-ts-eof.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,20 @@
# It can take a few frames for the syncer to actually produce a matched frameset (it doesn't
# know what to match to in the beginning)

# D C @timestamp comment
# -- -- ----------- ----------------
# 0 @0 so next expected frame timestamp is at 0+16.67
# 0 @0
#
sw.generate_depth_and_color( frame_number = 0, timestamp = 0 )
sw.expect( depth_frame = 0 ) # syncer doesn't know about color yet
sw.expect( color_frame = 0, nothing_else = True ) # less than next expected of D
#
# NOTE: if the syncer queue wasn't 100 (see above) then we'd only get the color frame!
# (it will output D to the queue, then C to the queue, but the queue size is 1 so we lose D)
#
# 1 @16
# 1 @16
#
sw.generate_depth_and_color( 1, sw.gap_d * 1 )
sw.expect( depth_frame = 1, color_frame = 1, nothing_else = True ) # frameset 1
Expand All @@ -40,6 +49,9 @@
#
test.start( "Keep going" )

# 2 @33
# 2 @33
#
sw.generate_depth_and_color( 2, sw.gap_d * 2 )
sw.expect( depth_frame = 2, color_frame = 2, nothing_else = True ) # frameset 2

Expand All @@ -49,6 +61,8 @@
#
test.start( "Stop giving color; nothing output" )

# 3 @50
#
sw.generate_depth_frame( 3, sw.gap_d * 3 )

# The depth frame will be kept in the syncer, and never make it out (no matching color frame
Expand Down

0 comments on commit 474a33a

Please sign in to comment.