Robotics StackExchange | Archived questions

rosbag image timestamp

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.

Asked by ARM on 2018-05-07 16:08:35 UTC

Comments

Answers

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.

Asked by PeteBlackerThe3rd on 2018-05-08 06:28:24 UTC

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!

Asked by ARM on 2018-05-09 09:04:50 UTC

Glad you got this working!

Asked by PeteBlackerThe3rd on 2018-05-09 12:27:37 UTC

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'])

Asked by ARM on 2018-05-09 09:07:23 UTC

Comments