ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

rosbag image timestamp

asked 2018-05-07 16:08:35 -0500

ARM gravatar image

I have a rosbag file which contain images and sensor data. I need to extract Images and their timestamp. And afterwards I want to use them to train Neural Network for classification purpose.

For this, I wrote a rosnode in Python, which subscribes to the image topic.

Images are extracted but how I can save timestamps.

Those images and their timestamp need to be uploaded into database.

Is this possible when playing rosbag file I can create a CSV file which saves the image name and their timestamp.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-05-08 06:28:24 -0500

Yes this definitely possible. To clarify the timestamp in ROS will be the number of seconds from the start of the bag file, not an absolute date like the unix timestamp.

Each image message includes a header data structure which contains the details of its coordinate frame and timestamp. You can access it's data members to get the time then format these into a string. You can either create a separate csv file to map times to image file names or you could write the timestamp directly into the file name.

edit flag offensive delete link more

Comments

Hi, you are right! I followed the following two approaches. One is Python code and another using operating system command within Python. Both had worked for me!

ARM gravatar image ARM  ( 2018-05-09 09:04:50 -0500 )edit

Glad you got this working!

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-05-09 12:27:37 -0500 )edit
0

answered 2018-05-09 09:07:23 -0500

ARM gravatar image

Method 1:

metadata = 'echo ' + str(msg.header.seq)+ ' , ' + str(msg.header.stamp) + ' , ${PWD}' + '/' +sys.argv[1]+'/frame_' + str(msg.header.stamp) + '.jpeg' + '>> ${PWD}' + '/' +sys.argv[1]+'/metadata.csv'

os.system(metadata)

Method 2:

with open('metadata.csv','ab') as f:
    thewriter = csv.writer(f)
    thewriter.writerow(['frame_id', 'seqno','stamp','name'] )
    thewriter.writerow([str(msg.header.frame_id), str(msg.header.seq),str(msg.header.stamp), 'frame_'+ str(msg.header.stamp) + '.jpeg'])
edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2018-05-07 16:08:35 -0500

Seen: 3,810 times

Last updated: May 09 '18