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

Saving Images with image_saver with timestamp

asked 2018-02-26 03:11:09 -0500

Baumboon gravatar image

updated 2018-02-26 04:34:07 -0500

Hello Guys,

i use linux 16.04 with ros kinetic and gazebo 7.0. I have a simulated turtlebot from the turtlebot package. I want to save the rgb images with timestamp like i can save the pcd files with timestamp.

At the moment i am using this to get the image:

rosrun image_view image_saver image:=/camera/rgb/image_raw

when i run this i get something like: left0000.jpg . So is it possible to get the images with timestamp ?

edit retag flag offensive close merge delete


I'm guessing you use image_saver, not image_view, correct?

gvdhoorn gravatar image gvdhoorn  ( 2018-02-26 04:07:55 -0500 )edit

yeah right copied code wrong i corrected it

Baumboon gravatar image Baumboon  ( 2018-02-26 04:27:52 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2018-02-26 11:26:44 -0500

Baumboon gravatar image

updated 2018-02-26 11:27:25 -0500

So with the help of gvdhoorn i found a solution:

First of all i found code for saving my images i take the code from this tutorial:

Image saver Ros

then i added some lines for the timestamp so it looked like:

#! /usr/bin/python
# Copyright (c) 2015, Rethink Robotics, Inc.

# Using this CvBridge Tutorial for converting
# ROS images to OpenCV2 images

# Using this OpenCV2 tutorial for saving Images:

# rospy for the subscriber
import rospy
# ROS Image message
from sensor_msgs.msg import Image
# ROS Image message -> OpenCV2 image converter
from cv_bridge import CvBridge, CvBridgeError
# OpenCV2 for saving an image
import cv2

# Instantiate CvBridge
bridge = CvBridge()

def image_callback(msg):
    print("Received an image!")
        # Convert your ROS Image message to OpenCV2
        cv2_img = bridge.imgmsg_to_cv2(msg, "bgr8")
    except CvBridgeError, e:
        # Save your OpenCV2 image as a jpeg 
        time = msg.header.stamp
        cv2.imwrite(''+str(time)+'.jpeg', cv2_img)

def main():
    # Define your image topic
    image_topic = "/camera/rgb/image_raw"
    # Set up your subscriber and define its callback
    rospy.Subscriber(image_topic, Image, image_callback)
    # Spin until ctrl + c

if __name__ == '__main__':
edit flag offensive delete link more


Great to hear that you got something to work, but realistically this is really a work-around, as image_saver itself does not support what you were asking.

gvdhoorn gravatar image gvdhoorn  ( 2018-02-26 11:27:56 -0500 )edit

I need this for machine learning, my thesis is about a simulated turtlebot which do some image recognition with tensorflow. So i needed rgb images and pcd files with the same time stamp. So it works semi well, i need the same clock speed like pcl publishes the pcd files. But i think i'll get i work

Baumboon gravatar image Baumboon  ( 2018-02-26 11:33:25 -0500 )edit

:) I wasn't criticising anything, just observing that you wrote that you found a solution. Your question is about getting image_saver to store files with a timestamp, but that is not possible (right now). So strictly speaking there is no solution to your question. That's what I was pointing out.

gvdhoorn gravatar image gvdhoorn  ( 2018-02-26 11:40:48 -0500 )edit

Yeah thats correct, maybe they will add this in the future.

Baumboon gravatar image Baumboon  ( 2018-02-26 16:23:36 -0500 )edit

There is a much higher chance of that happening if you either:

gvdhoorn gravatar image gvdhoorn  ( 2018-02-27 02:46:01 -0500 )edit

@Baumboon hey did you habe a github account or a e-mail address for questions, i don't want to spam here everything with my questions

Petros ADLATUS gravatar image Petros ADLATUS  ( 2022-03-30 06:35:09 -0500 )edit

answered 2018-02-26 04:12:57 -0500

gvdhoorn gravatar image

updated 2018-02-26 04:37:54 -0500

From a look at the code (image_saver.cpp) it doesn't look like including the timestamp in the filename is supported right now.

The video_recorder node does support adding a timestamp since ros-perception/image_pipeline#203. Perhaps that approach could be ported to image_saver.cpp, but note that image_saver uses boost::format.

Note btw that sensor_msgs/Image does not have a header, so any timestamp added would be the time at which the message is received, not the stamp at which it was published.

Edit: I misremembered, sensor_msgs/Image does have a Header, so the stamp should be there (if set by the publishing node of course). See sensor_msgs/Image.

edit flag offensive delete link more


Is there a way to get rgb images with timestamp when it was published? I need the correct rgb image that fits to the pcd file. I trying to make some machine learning task for my robot thats why i need it

Baumboon gravatar image Baumboon  ( 2018-02-26 04:31:03 -0500 )edit

I am struggeling now how to go on right. Would it be correct to modify the image_saver.cpp that it is possible to save images with timestamp ? So i need to access to the header of the topic correct ?

Baumboon gravatar image Baumboon  ( 2018-02-26 05:04:11 -0500 )edit

Yes, you could try to see how you'd access that information. You could consider passing the timestamp of the incoming Image msg to the saveImage(..) method that is used by both callbacks in image_saver.cpp.

gvdhoorn gravatar image gvdhoorn  ( 2018-02-26 05:07:33 -0500 )edit

If you get this to work it would be +100 if you'd then submit a PR against perception/image_pipeline to add this to the 'official' node.

gvdhoorn gravatar image gvdhoorn  ( 2018-02-26 05:08:06 -0500 )edit

found this solution for video_recorder :

timestamp video recorder

will this work similar for image_saver?

Baumboon gravatar image Baumboon  ( 2018-02-26 10:17:38 -0500 )edit

tried it on a python node where i save pics and it works, so it should also work for image_saver i think

Baumboon gravatar image Baumboon  ( 2018-02-26 11:06:30 -0500 )edit

That is what I linked to in my answer, it's the changes introduced in PR image_pipeline#203. That could work, but it uses ros::Time::now(), which is not what you want. You'd need to change that to use the stamp in the header of the received Image msg.

gvdhoorn gravatar image gvdhoorn  ( 2018-02-26 11:06:40 -0500 )edit

Thank u so much, i think i found a solution that works. Now i have pcd files and image files with the same timestamp. I post the code in a seperate answer

Baumboon gravatar image Baumboon  ( 2018-02-26 11:07:48 -0500 )edit

answered 2019-02-23 07:50:18 -0500

Check the following repo you can save images with the time stamp

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-02-26 03:11:09 -0500

Seen: 15,639 times

Last updated: Feb 23 '19