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

Revision history [back]

First, I'd advise against saving the map as .jpg as that introduces compression artifacts that look bad and can mess with further processing (or the eye of the beholder ;) ).

If you absolutely want to directly save the map as jpg, the easiest way is probably to copy/modify the map_saver, add a dependency on opencv, convert the map to a cv::Mat in the map callback and then write it out as jpg. Here is code for converting a nav_msgs/OccupancyGrid to cv::Mat and here is an example of saving a cv::Mat to jpg.

A easier option is of course to use a command-line tool such as convert. It should do the conversion from command line or inside a script by simple calling

convert map.pgm map.jpg

First, I'd advise against saving the map as .jpg as that introduces compression artifacts that look bad and can mess with further processing (or the eye of the beholder ;) ).

If you absolutely want to directly save the map as jpg, the easiest way is probably to copy/modify the map_saver, add a dependency on opencv, convert the map to a cv::Mat in the map callback and then write it out as jpg. Here is code for converting a nav_msgs/OccupancyGrid to cv::Mat and here is an example of saving a cv::Mat to jpg.

A easier option is of course to use a command-line tool such as convert. It should do allow to perform the conversion from command line or inside a script by simple simply calling

convert map.pgm map.jpg