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

Merging Multiple PointCloud2

asked 2013-03-19 13:10:59 -0500

superawesomepandacat gravatar image

updated 2013-03-19 13:15:14 -0500

Is there a way to merge two different PointCloud2 messages? Assuming they are defined in the same frame of course.

edit retag flag offensive close merge delete

Comments

2

You just want to combine the points?

joq gravatar image joq  ( 2013-03-19 16:42:42 -0500 )edit

Sorry for the late reply. Yes, given the point cloud data in two different PointCloud2 messages (or pcl::PointCloud type), how do I combine them into one.

superawesomepandacat gravatar image superawesomepandacat  ( 2013-03-20 11:58:11 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
5

answered 2013-03-20 19:21:11 -0500

updated 2013-03-21 03:03:03 -0500

I think you are looking for concatenatePointCloud.

Or, you may be able to just do: combined = cloudA + cloudB, as shown in this tutorial.

Edit:
The tutorial referenced above also shows how to merge to point clouds with different fields, using concatenateFields. The restriction here is that the two point clouds must contain the same number of points.

As far as octomapping, the main focus of that entire package is to address the concerns of fusing 3D data (e.g. point clouds) in a space- and performance-efficient way. The approach is described well in this paper. Basically, they recursively divide the environment into smaller subdivisions, which allows them to "grow" the map as new data is added. They also store probabalistic data rather than explicit data points, to allow them to efficiently merge multiple sensor readings for the same "point" and ignore false/transient readings.

Merging raw point clouds is faster than octomapping, but can quickly run into memory and performance limitations, as all sensor data is maintained. Other approaches exist to address these issues for particular use-cases, such as voxels, 2.5D surface mapping, etc. Many of these are also given a brief overview in the octomapping paper listed above.

edit flag offensive delete link more

Comments

1

Thanks, that's an answer. But what if the number of fields of the point clouds are different? How do packages like octomapping gradually build up a point cloud of the environment over time? Do they just store all the point clouds captured at each time and then display them simultaneously?

superawesomepandacat gravatar image superawesomepandacat  ( 2013-03-20 23:13:00 -0500 )edit

i have followed the tutorial and merged two pointclouds. (tilting laser and static kinect). but now i have tf problem with output cloud. it is tilting all the cloud.. Any advice would be most welcome..

fatihx gravatar image fatihx  ( 2013-09-04 22:41:30 -0500 )edit
2

The link to concatenatePointCloud is a dead link. I believe this is the correct link to the current version in PCL 1.11: concatenatePointCloud. However, it must be noted that this works with the pcl::PCLPointCloud2 data type, NOT the ROS sensor_msgs::PointCloud2

M@t gravatar image M@t  ( 2020-12-13 16:17:07 -0500 )edit
1

Now it also works with sensor_msgs::PointCloud2 using bool concatenatePointCloud (const sensor_msgs::PointCloud2 &cloud1, const sensor_msgs::PointCloud2 &cloud2,sensor_msgs::PointCloud2 &cloud_out) from pcl_conversions.h

ignacio gravatar image ignacio  ( 2021-06-18 08:49:16 -0500 )edit
2

answered 2020-12-13 16:31:57 -0500

M@t gravatar image

updated 2020-12-13 17:36:22 -0500

I am making an assumption in answering this question: You want to merge (NOT register) the two clouds. I.e. combine their points into one point object without transforming the points in any way.

Next, the answer depends on which "PointCloud2" datatype you are referring to. Both ROS and PCL (Point Cloud Library) have their own definitions of a data type with this name. The options available to you are different depending on which you are using.

pcl::PCLPointCloud2

To merge two pcl::PCLPointCloud2 clouds, you have the following options:

// Option 1
MergedCloud = Cloud1 + Cloud2

// Option 2
MergedCloud += Cloud1

// Option 3
pcl::PCLPointCloud2::concatenate(MergedCloud, Cloud1)

// Option 4 
pcl::PCLPointCloud2::concatenate(Cloud1, Cloud2, MergedCloud)

Source: pcl::PCLPointCloud2 Struct Reference

sensor_msgs::PointCloud2

To merge two ROS sensor_msgs::PointCloud2 clouds, there aren't any pre-existing functions that will do this for you (unless I missed them) so you have to either convert the point cloud to a PCL type (plenty of online tutorials that will show you how to do that) or you have to do it yourself directly. In C++ this can be done as shown below:

Note: I am assuming here that you are using an unorganized point cloud, in which case the "width" is just the length of the 1D data array. Merging organised point clouds is very different and deserves its own Q&A.

// Merge metadata
MergedCloud.width += Cloud1.width;

// Re-size the merged data array to make space for the new points
uint64_t OriginalSize = MergedCloud.data.size();
MergedCloud.data.resize(MergedCloud.data.size() + Cloud1.data.size());

// Copy the new points from Cloud1 into the second half of the MergedCloud array
std::copy(
  Cloud1.data.begin(),
  Cloud1.data.end(),
  MergedCloud.data.begin() + OriginalSize);
edit flag offensive delete link more

Comments

does anybody translate it to python or can tell me the installation commans? I want to combine sensor_msgs/PointCloud2 from LiDAR.

Petros ADLATUS gravatar image Petros ADLATUS  ( 2022-04-22 03:34:37 -0500 )edit
1

answered 2013-05-30 20:16:29 -0500

Sentinal_Bias gravatar image

http://www.ros.org/wiki/pointcloud_registration

you could try an ICP based approach so you can ignore point-clouds who overlap too much

I am trying to use the above package but it doesn't build for some reason

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2013-03-19 13:10:59 -0500

Seen: 18,318 times

Last updated: Dec 13 '20