Skip to content

Commit

Permalink
Add option to use rosbag timestamp rather than header.stamp
Browse files Browse the repository at this point in the history
  • Loading branch information
amarburg committed Nov 26, 2024
1 parent 1fb177f commit 8d6345e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
7 changes: 7 additions & 0 deletions rosbags2video/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def argparser_common(which_output):
type=float,
help="Rostime representing where to start in the bag.",
)

parser.add_argument(
"--end",
"-e",
Expand All @@ -61,6 +62,12 @@ def argparser_common(which_output):
help="Logging level. Default INFO.",
)

parser.add_argument(
"--bag-time",
action="store_true",
help="Use bagfile time rather than header.stamp",
)

parser.add_argument(
"--timestamp", action="store_true", help="Write timestamp into each image"
)
Expand Down
8 changes: 7 additions & 1 deletion rosbags2video/bag2images.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def write_frames(
viz=False,
encoding="bgr8",
skip=1,
use_bagtime=False,
):
convert = {topics[i]: i for i in range(len(topics))}

Expand All @@ -52,7 +53,11 @@ def write_frames(
):
topic = connection.topic
msg = bag_reader.deserialize(rawdata, connection.msgtype)
time = stamp_to_sec(msg.header.stamp)

if use_bagtime:
time = t / 1e9
else:
time = stamp_to_sec(msg.header.stamp)

logging.debug("Topic %s updated at time %s seconds" % (topic, time))

Expand Down Expand Up @@ -114,6 +119,7 @@ def main():
stop_time=stop_time,
encoding=args.encoding,
skip=args.skip,
use_bagtime=args.bag_time,
)

logging.info("Done.")
Expand Down
11 changes: 9 additions & 2 deletions rosbags2video/bag2video.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def write_frames(
start_time=0,
stop_time=sys.maxsize,
add_timestamp=False,
use_bagtime=False,
):
convert = {topics[i]: i for i in range(len(topics))}
frame_duration = 1.0 / fps
Expand All @@ -49,9 +50,14 @@ def write_frames(
):
topic = connection.topic
msg = bag_reader.deserialize(rawdata, connection.msgtype)
# print(f'DEBUG: {msg.header.stamp}')
# print(f'DEBUG: {msg.header.stamp}, {t}')
# exit(0)
time = stamp_to_sec(msg.header.stamp)

if use_bagtime:
time = t / 1e9
else:
time = stamp_to_sec(msg.header.stamp)

if init:
image = message_to_cvimage(msg, encoding)
images[convert[topic]] = image
Expand Down Expand Up @@ -181,6 +187,7 @@ def main():
start_time=args.start,
stop_time=args.end,
add_timestamp=args.timestamp,
use_bagtime=args.bag_time,
)
logging.info("Done.")
bag_reader.close()
Expand Down

0 comments on commit 8d6345e

Please sign in to comment.