Ask Your Question

How to create a map using raw point cloud data?

asked 2018-02-16 04:14:41 -0500

pallyra1 gravatar image

updated 2018-02-17 02:33:29 -0500


I have a raw point cloud data stored in a rosbag file. How can I generate a map from this rosbag file? Also, that raw point cloud data has redundant information. How can I extract only the required information and create a map?

Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-02-18 18:09:03 -0500

kkrasnosky gravatar image

updated 2018-02-19 09:00:43 -0500

I recommend using the octomap_server . This will filter redundant points by binning them into a 3d occupancy grid. You can watch the results in rViz as the map generates too which is handy for debugging. I have been using it process sonar point clouds from an ROV with decent results.

Octomap has a nice c++ api if you prefer to do things manually.


  1. Start the octomap_sever ros node
  2. play your rosbag file back
  3. open rViz to see whats going on. Subscribe to the occupied_cells_vis_array topic.

I included an example launch file to help you out, you will probably need to remap your point cloud topic to cloud_in:

    <node name="octomap" pkg="octomap_server" type="octomap_server_node">
        <param name="frame_id" value="/odom"/>
        <param name="resolution" value=".4"/>


if you want to go the c++ route with rosbag or want to read in a .pcd file you probably want to do something like this. You can then use octovis to open the octomap and view it.

#include <octomap/octomap.h>
#include <octomap/OcTree.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_types.h>
#include <pcl/PCLPointCloud2.h>
#include <pcl/conversions.h>

int main(int argc, char *argv[])

    ros::init(argc, argv, "pcl2octo");

    octomap::OcTree tree (0.1);   // declare your octomap at 0.1 resolution

    // read in your data here either rosbag or pcl

    for(/* enter conditoins here */){  // crate a loop for each sensor measurement taken

        pcl::PointCloud<pcl::PointXYZ> pt; // populate this with the point cloud from one sensor ping
        octomap::point3d sensorOrigin(x,y,z); // where x,y,z are the location of the sensor for that measurement

        for (pcl::PointCloud<pcl::PointXYZ>::const_iterator it = pt.begin(); it != pt.end(); ++it){
          cloud.push_back(it->x, it->y, it->z);


    return 0;


I hope that helps.

edit flag offensive delete link more



Thank you for the recommendation. I tried to use octomap. Can you explain this line a bit, binning them into a 3d occupancy grid? Furthermore, I have data in .pcd format. How to change the format? And also, how to visualise octree using rviz?

pallyra1 gravatar image pallyra1  ( 2018-02-19 05:03:04 -0500 )edit

When I say "binning" I mean octomap divides the world into a 3D grid of voxels. It then determines the likelihood that a voxel based on your point cloud. I thought you had your data in a rosbag file? Could you describe your sensor and data setup in a little more detail?

kkrasnosky gravatar image kkrasnosky  ( 2018-02-19 08:34:43 -0500 )edit

I am very new to ros. we are trying to make autonomous vehicle. We have collected data (point cloud) using a camera. My main aim is to make a map out of it. When i use the command rosrun octomap_server octomap_server_node.. I get this error..

pallyra1 gravatar image pallyra1  ( 2018-02-20 01:16:52 -0500 )edit

Publishing latched (single publish will take longer, all topics are prepared) Nothing to publish, octree is empty

And how to remap the data using that launch file? I am very new to the concepts.. I have to ask these questions

pallyra1 gravatar image pallyra1  ( 2018-02-20 01:17:56 -0500 )edit

The rosbag file has /points_raw topic.. How to use the launch file to remap to cloud_in?

pallyra1 gravatar image pallyra1  ( 2018-02-20 01:29:16 -0500 )edit

You are getting that error because the octomap didn't receive any points yet. You can remap using:

<remap from="points_raw" to="cloud_in" />

if you are still having trouble you can see where messages are going by running:

rosrun rqt_graph rqt_graph
kkrasnosky gravatar image kkrasnosky  ( 2018-02-26 10:27:52 -0500 )edit


Hope you have managed to solve your problem now. If you don't mind can you share the solution of your problem with me? cause I have the same problem and my team and I wanna extract an occupancy grid map from a camera having pointcloud2 message being published.


Thank you.

Mennaa gravatar image Mennaa  ( 2020-12-19 01:37:44 -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



Asked: 2018-02-16 04:14:41 -0500

Seen: 7,340 times

Last updated: Feb 19 '18