# Script based on this post: # https://stackoverflow.com/questions/76537425/how-to-export-image-and-video-data-from-a-bag-file-in-ros2 # Arnoud - Nov 2024 - Adjusted to work in the current diretory based on rae-topic. from rosbags.highlevel import AnyReader from pathlib import Path import cv2 from rosbags.image import message_to_cvimage count = 0 with AnyReader([Path('.')]) as reader: # topic and msgtype information is available on .connections list for connection in reader.connections: print(connection.topic, connection.msgtype) for connection, timestamp, rawdata in reader.messages(): if connection.topic == '/rae/right/image_raw/compressed': # topic Name of images msg = reader.deserialize(rawdata, connection.msgtype) img = message_to_cvimage(msg, 'bgr8') # change encoding type if needed cv2.imwrite("images/frame%06i.jpg" % count, img) count += 1