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

RVIZ display 2d probabilistic map

asked 2012-02-06 21:49:15 -0500

acp gravatar image

Hi Everybody.

I wonder how RVIZ can display a 2d probabilistic map.

I have a 2D matrix where I store the probabilistic values of an occupancy grid map. What can I use to display this values in RVIZ?


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2012-02-07 01:09:57 -0500

updated 2012-02-07 06:34:08 -0500

The rviz map plugin unfortunately currently only supports the three discrete states unknown, occupied and free. See this code snipped from visualization/rviz/src/rviz/default_plugin/map_display.cpp (starting at line 289):

  for( unsigned int pixel_index = 0; pixel_index < num_pixels_to_copy; pixel_index++ )
    unsigned char val;
    if(msg->data[ pixel_index ] == 100)
      val = 0;
    else if(msg->data[ pixel_index ] == 0)
      val = 255;
      val = 127;

    pixels[ pixel_index ] = val;

It is thus currently not possible to use nav_msgs/OccupancyGrid.msg messages and display more than these 3 states/color values in rviz. However, one could use the existing map_display plugin as a starting point for a modified version that displays more levels of grey. Only changing the above loop would be necessary for that (if you want to keep using standard nav_msgs/OccupancyGrid messages).

edit flag offensive delete link more


In advance, thank you for your replay, I have the idea to visualize the probabilistic matrix using sensor_msgs::PointCloud, and actually I can visualize the matrix in rviz, the only thing is that it does not display gray colours.
acp gravatar image acp  ( 2012-02-07 17:21:02 -0500 )edit
I was thinking about to somehow assign grey colours to each individual point coordinate that correspond to the probability value. I do not know if that is possible.
acp gravatar image acp  ( 2012-02-07 17:23:16 -0500 )edit
It is possible to add the color information via the channel array in a sensor_msgs::PointCloud ( see for example You could also use a sensor_msgs::PointCloud2. In that case, you could take kinect data as an example.
Stefan Kohlbrecher gravatar image Stefan Kohlbrecher  ( 2012-02-07 18:06:04 -0500 )edit
Hi, the content of above mentioned links are a bit confused, just wondering whether you may have a piece of code I can take a look at, thank you
acp gravatar image acp  ( 2012-02-07 21:36:07 -0500 )edit

probabilities are in the range [0,100], which means the occupancy grid values dont have to take discrete states. You can have a an occupancy value of 90 ie a probability of 0.9. Therefore you can use occupancy grid msg to render probability maps. Everything will just be in gray scale

Sentinal_Bias gravatar image Sentinal_Bias  ( 2014-04-22 16:46:27 -0500 )edit

answered 2012-02-07 00:52:38 -0500

DimitriProsser gravatar image

updated 2012-02-08 01:15:28 -0500

ROS costmaps are typically visualized using nav_msgs/GridCells. If you were to fill one of these data structures with your probabilistic map, you would be able to visualize it in Rviz in three colors (INFLATED, OCCUPIED, UNKNOWN).

What I did to visualize probabilistic maps, however, was simply to save my data structure as an image file (with OpenCV) and then view it as a sensor_msgs/Image. This is a pretty hacky solution, but I needed to save them as images anyway, so it worked for me.


To convert my costmap-like data structure to an OpenCV image, I simply just set each costmap cell as a pixel in an OpenCv IplImage data structure. Then, you can just cv_bridge to convert that image to a sensor_msgs/Image. This is simple to do if you know OpenCv, but you might have to do some research on the OpenCv image data structure. It's not too complex.

It should be noted that the Image in Rviz is in a separate window from the robot body. You won't be able to overlay one on the other using this method.

edit flag offensive delete link more


I think that the GridCells message gets assigned a fixed color by rviz (you can choose it), whereas the OccupancyGrid uses the three different obstacle types.
Eric Perko gravatar image Eric Perko  ( 2012-02-07 10:47:57 -0500 )edit
In advance thank you for your replay, do you have some example code how to save an structure to as an image file and then send it as a sensor_msgs/Image topic.
acp gravatar image acp  ( 2012-02-07 17:25:54 -0500 )edit
I want to refresh the matrix often, I mean the map hast to be dynamic, just wondering if the process of saving and uploading does not expensive.
acp gravatar image acp  ( 2012-02-07 17:26:43 -0500 )edit

Question Tools

1 follower


Asked: 2012-02-06 21:49:15 -0500

Seen: 5,589 times

Last updated: Feb 08 '12