Ask Your Question
0

How to save the map as jpg format

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

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 -0500

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

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 -0500 )edit
0

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

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 -0500 )edit

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: 2016-01-12 01:57:41 -0500

Seen: 643 times

Last updated: Jan 12 '16