How to use image_saver to save images into different folders rather than all in than the same one?
I’m using ROS kinetic
and gazabo
simulator. I have a functional simulation program that can save all images from drone’s camera into same path using the “image_saver”
of the “image_view”
package, for example saving “image_1” to “folder_1”, “image_2” to “folder_1” and so on. My goal is to modify this program so that it can save images from camera into different paths, for example saving “image_1” to “folder_1”, “image_2” to “folder_2” etc.
What I was thinking is to change the value of the “filename_format”
every time before I call the “save”
service, but it didn’t work, the program is still saving all the images into the folders corresponding to the “filename_format”
initiative value when the simulation started. It seems that changing the value of the “filename_format”
during the simulation’s running will not change the path that the “save”
service is about to save to.
I got stuck on how to proceed, below are the core code that I’m using to save the images.
Much obliged.
.launch file:
<node pkg="image_view" type="image_saver" name="image_saver" output="screen">
<!--<param name="filename_format" value="/home/donghao/Aniketh/wallBot/droneSim/catkin_ws/capture/exp6/capture%02i.jpg"/> -->
<param name="save_all_image" value="false"/>
<remap from="image" to="/firefly/camera_nadir/image_raw" />
</node>
<node name="goal2goal" pkg="rotors_gazebo" type="goal2goal" output="screen"/>
<node name="image_view" pkg="image_view" type="image_view" respawn="false" output="screen">
<remap from="image" to="/firefly/camera_nadir/image_raw" />
</node>
.cpp file
Int j = 1;
std_srvs::Empty srv;
while(j <= 15){
// folder generator
vector <string> im_location;
int first = (j)/10;
int second = (j)%10;
int image_num = 0;
dir = "/home/donghao/Aniketh/wallBot/droneSim/catkin_ws/capture/exp1/trial"+ ("{}",to_string(first)) + ({}",to_string(second));
//setting the parameter in the image saver node to change the dir of the saved images
ros::param::set("/firefly/image_saver/filename_format" , dir+"/frame%04i.jpg");
ros::param::get("/firefly/image_saver/filename_format" , new_dir);
ros::Duration(0.1).sleep();
for (int i = 0; i < waypoints.size(); i++){
//flying through the waypoints
mav_msgs::msgMultiDofJointTrajectoryFromPositionYaw(waypoints[i].position, waypoints[i].yaw, &trajectory_msg);
//saving image
if(i%3==0){
int first = (image_num)/10;
int second = (image_num)%10;
string data = "capture"+("{}",to_string(first)) + ("{}",to_string(second)) + ", " + position_message + "," + orientation_message;
im_location.push_back(data);
bool save=ros::service::call("/firefly/image_saver/save",srv);
image_num++;
}
trajectory_pub.publish(trajectory_msg);
actuator_pub.publish(actuator_msg);
ros::Duration(0.3).sleep();
}
ros::spinOnce();
j++;
}