How to read data(point cloud) from ouster rosbag file(.db3)?
yangxingjian opened this issue · 1 comments
yangxingjian commented
I am trying to use sqlite3 to access the dataframe (specifically the point cloud frames) within the recorded .db3 rosbag, and it seems that for single frame data of the topic "/ouster/points", the extracted data is serialized, is there any way to convert it to format such as hxwx3 numpy array point cloud or directly extract the deserialized data?
code I use:
import sqlite3
def get_messages_for_topic(conn, topic_name):
cursor = conn.cursor()
# Get topic ID first
cursor.execute("SELECT id FROM topics WHERE name = ?", (topic_name,))
topic_id = cursor.fetchone()
if topic_id:
topic_id = topic_id[0]
# Now fetch messages for this topic
cursor.execute("SELECT timestamp, data FROM messages WHERE topic_id = ?", (topic_id,))
messages = cursor.fetchall()
else:
messages = []
cursor.close()
return messages
def main():
db_path = 'path_to_your_bag_file.db3'
conn = sqlite3.connect(db_path)
try:
topic_name = '/ouster/points'
messages = get_messages_for_topic(conn, topic_name)
print(f"Messages for {topic_name}:")
for timestamp, data in messages:
print(f"Timestamp: {timestamp}, Data Length: {len(data)} bytes")
finally:
conn.close()
if __name__ == '__main__':
main()
Samahu commented
When using ROS and python you can rely on point_cloud2 to read PointCloud2 objects using the pc2.read_points
method and construct a numpy array out of it.
Hope this helps!