Converting occupancy grid to image

asked 2017-06-19 07:52:10 -0600

juanlu gravatar image

updated 2017-06-19 08:25:52 -0600

lucasw gravatar image


Using the grid_map libraries I am converting a map in the form of an occupancy grid to an image in order to store it in a database.

The occupancy grid has the following format:

100 is a wall

0 is free space

-1 is unknown space

The problem that I am having is that I don't manage to keep the unknown space information in the image as it always transforms it into black pixels. This is the code I am using:

grid_map::GridMap temporal_grid_map;
grid_map::GridMapRosConverter::fromOccupancyGrid(occupancy_grid, "elevation", temporal_grid_map);
cv::Mat temporal_image;
grid_map::GridMapCvConverter::toImage<unsigned char, 1>(
    temporal_grid_map, "elevation", CV_8UC1, 100, 0, temporal_image);

Any idea?


P.S. Here an imshow of the occurence. Outside of the walls it should be light grey, or at least it should be somehow different than the walls.


edit retag flag offensive close merge delete


1 shows a CV_8UC3 color image as the destination encoding, maybe that will render the unknown space as a color?

lucasw gravatar image lucasw  ( 2017-06-19 08:37:23 -0600 )edit

Though at first glance I'm not seeing anything in to handle -1/unknown values.

lucasw gravatar image lucasw  ( 2017-06-19 08:40:19 -0600 )edit

Me neither. I think the problem is in the fact that they don't allow non unsigned types and therefore the -1 values dissapear.

juanlu gravatar image juanlu  ( 2017-06-20 02:35:20 -0600 )edit

It wouldn't be too hard to create your own cv::Mat and copy the values out, and make up your own assignment for -1. You could also copy straight across into a signed type Mat but the options for saving that to disk are limited, and your database may not like it.

lucasw gravatar image lucasw  ( 2017-06-20 15:03:51 -0600 )edit