How to convert a python matrix to rosbag format?

asked 2020-09-07 01:32:15 -0500

samiarja gravatar image

updated 2020-09-07 06:37:20 -0500

I have a python array which consists of 4 columns (x, y, polarity, timestamp) with an n number of rows. I want to convert it to rosbag (.bag) format so I can use it in a ROS package. The new .bag file should have similar properties as the existing .bag.

I checked the .bag file property by using the following command:

rosbag info /home/sami/sami/Dataset/bag/calib_outdoor_infrared.bag

path:        calib_outdoor_infrared.bag
version:     2.0
duration:    7.1s
start:       Apr 16 2019 01:09:18.58 (1555340958.58)
end:         Apr 16 2019 01:09:25.70 (1555340965.70)
size:        195.7 MB
messages:    787
compression: none [227/227 chunks]
types:       dvs_msgs/EventArray [5e8beee5a6c107e504c2e78903c224b8]
             sensor_msgs/Image   [060021388200f6f0f447d0fcd9c64743]
topics:      /dvs/events        215 msgs    : dvs_msgs/EventArray
             /dvs/image_color   286 msgs    : sensor_msgs/Image  
             /dvs/image_raw     286 msgs    : sensor_msgs/Image

This is how I read my data as as a NumPy array:

import loris

# Read es files
my_file = loris.read_file("/home/sami/sami/Dataset/es/HIE-2020_03_09_15_48_39.aedat4.es")

# events is now a numpy array
events = my_file['events']

# Print all array components
for event in events:
    print("ts:", event.t, "x:", event.x, "y:", event.y, "p:", event.p)

# write x, y, polarity and timestamp to .bag file
....

This is the content of the file:

ts: 99803 x: 198 y: 212 p: False
ts: 99805 x: 183 y: 84 p: False
ts: 99806 x: 275 y: 29 p: True
ts: 99807 x: 46 y: 52 p: True
ts: 99808 x: 118 y: 70 p: True
ts: 99811 x: 239 y: 64 p: True
ts: 99817 x: 230 y: 21 p: True
ts: 99817 x: 261 y: 54 p: False
ts: 99819 x: 16 y: 1 p: False
ts: 99819 x: 272 y: 135 p: True
ts: 99820 x: 242 y: 46 p: False
ts: 99821 x: 173 y: 196 p: True
ts: 99822 x: 268 y: 37 p: True
ts: 99823 x: 49 y: 94 p: True
ts: 99823 x: 129 y: 3 p: False
ts: 99824 x: 96 y: 73 p: True
ts: 99826 x: 122 y: 88 p: True
ts: 99826 x: 20 y: 155 p: False
ts: 99827 x: 320 y: 14 p: True
ts: 99827 x: 81 y: 13 p: False
ts: 99828 x: 87 y: 91 p: False
ts: 99828 x: 277 y: 28 p: True

What will be the best way to convert this array to a .bag file with the same property?

I have a python array which consists of 4 columns (x, y, polarity, timestamp) with an n number of rows. I want to convert it to rosbag (.bag) format so I can use it in a ROS package. The new .bag file should have similar properties as the existing .bag.

I checked the .bag file property by using the following command:

rosbag info /home/sami/sami/Dataset/bag/calib_outdoor_infrared.bag

path:        calib_outdoor_infrared.bag
version:     2.0
duration:    7.1s
start:       Apr 16 2019 01:09:18.58 (1555340958.58)
end:         Apr 16 2019 01:09:25 ...
(more)
edit retag flag offensive close merge delete