0
$\begingroup$

Rosanswers logo

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


Originally posted by superawesomepandacat on ROS Answers with karma: 172 on 2013-03-19

Post score: 6


Original comments

Comment by joq on 2013-03-19:
You just want to combine the points?

Comment by superawesomepandacat on 2013-03-20:
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.

$\endgroup$

3 Answers 3

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Jeremy Zoss with karma: 4976 on 2013-03-20

This answer was ACCEPTED on the original site

Post score: 5


Original comments

Comment by superawesomepandacat on 2013-03-20:
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?

Comment by fatihx on 2013-09-04:
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..

Comment by M@t on 2020-12-13:
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

Comment by ignacio on 2021-06-18:
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

$\endgroup$
0
$\begingroup$

Rosanswers logo

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


Originally posted by Sentinal_Bias with karma: 418 on 2013-05-30

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

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);

Originally posted by M@t with karma: 2327 on 2020-12-13

This answer was NOT ACCEPTED on the original site

Post score: 2


Original comments

Comment by Petros ADLATUS on 2022-04-22:
does anybody translate it to python or can tell me the installation commans? I want to combine sensor_msgs/PointCloud2 from LiDAR.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.