Ask Your Question
0

Taking Gazebo screenshots using a ROS node

asked 2017-02-24 06:00:37 -0500

hansolo gravatar image

I'm using Gazebo to make some experiments. I want to take photos of Gazebo simulation in certain moments (decided by my ROS node). Gazebo has a screen capture utility by itself, it can be activated using a GUI button. However, there doesn't seem to be a ROS message or service to trigger it from a ROS node. Am I missing something?

Otherwise, can you suggest me the most modular way to take screenshots of whole screen? Can I create a shell script and rosrun it like a node when necessary? Or should I call screenshot application directly from my ROS node using C++?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2018-01-12 09:34:26 -0500

hansolo gravatar image

As there is no answer, I am sharing how I solved it back then.

I decided to create a shell script to handle the screenshots. During the execution, ROS node (C++ program) calls the shell file with a system call:

string path_str = ros::package::getPath("package_name");
string cmd_str = path_str+"/src/capture_screenshot.sh";

// add path and name arguments
cmd_str += " -p " + path_str + "/output";
cmd_str += " -n " + name_str;

// call the script program
system(cmd_str.c_str());

Shell script parses the arguments to create output file's path and captures Gazebo's screen:

# read arguments etc...

mkdir -p ${OUTPUT_PATH}

# take the screenshot
import -window Gazebo "${OUTPUT_PATH}/${OUTPUT_NAME}.jpg"

You can use additional arguments to tell script to create a new folder or not. Hope it will be helpful.

edit flag offensive delete link more

Comments

2

Nice of you to report back how you solved this.

It would probably be good to mention that import is one of the ImageMagick utilities, and that on Ubuntu it's distributed in the imagemagick package.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-12 09:39:22 -0500 )edit
0

answered 2018-01-12 21:57:20 -0500

string path_str = ros::package::getPath("package_name"); string cmd_str = path_str+"/src/capture_screenshot.sh";

// add path and name arguments cmd_str += " -p " + path_str + "/output"; cmd_str += " -n " + name_str;

// call the script program system(cmd_str.c_str());

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-02-24 06:00:37 -0500

Seen: 458 times

Last updated: Jan 12 '18