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

How to save the map as jpg format

asked 2016-01-12 01:57:41 -0600

tanghz gravatar image

Now ROS saves the robot map as pgm format, but I want to save the map as jpg format, I konw I could use the opencv to convert the "pgm map" to the "jpg map", but if I could save the map as jpg format in the map_saver code directly, it would be better. However, I know little about picture format and it's difficult for me to write the code by myself.

Thank you very much!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-01-12 03:07:20 -0600

updated 2016-01-12 06:49:13 -0600

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 allow to perform the conversion from command line or inside a script by simply calling

convert map.pgm map.jpg
edit flag offensive delete link more

Comments

Thank you very much!

tanghz gravatar image tanghz  ( 2016-01-12 04:40:39 -0600 )edit
0

answered 2016-01-12 03:03:45 -0600

Ariel gravatar image

You can open it with GIMP and the go to File->Export As and there you can select to export it as jpg.

edit flag offensive delete link more

Comments

Thank you very much! I will have a try.

tanghz gravatar image tanghz  ( 2016-01-12 04:41:39 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-01-12 01:57:41 -0600

Seen: 1,437 times

Last updated: Jan 12 '16