How to use image_saver to save images into different folders rather than all in than the same one?

asked 2022-02-08 11:53:33 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

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 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" />

.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);


    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
            int first = (image_num)/10;
            int second = (image_num)%10;
            string data = "capture"+("{}",to_string(first)) + ("{}",to_string(second)) + ", " + position_message + "," + orientation_message;
            bool save=ros::service::call("/firefly/image_saver/save",srv);
edit retag flag offensive close merge delete