cv_bridge and timestamps
I am trying to add timestamps to a Image message
The Image message has a header member and this has a stamp member
Two-integer timestamp that is expressed as: * stamp.sec: seconds (stamp_secs) since epoch (in Python the variable is called 'secs') * stamp.nsec: nanoseconds since stamp_secs (in Python the variable is called 'nsecs') time-handling sugar is provided by the client library
however the data that I ve received was originally extracted from a rosbag like this
for topic,msg,t in bag.read_messages():
timestamp= t.to_sec()
This gives a number like 1625151029.99
How can I take this number and put it in the timestamp of the Image message?
EDIT
for topic, msg, t in rosbag.read_messages():
timestamp= t
break
print("original")
print(timestamp)
print("recoreded")
ts= timestamp.to_sec()
print(ts)
print("back to timestamp")
print(rospy.Time.from_sec(ts))
#from here we record the timestamp
#Sorry unverified code
with open("afile.txt",'w') as f:
f.write('{0}\n'.format(ts))
with open("afile.txt",'r') as f:
new_ts=int(f.read())
print("recovered")
print(rospy.Time.from_sec(new_ts))
In this code we can see that the recovered value is different