Merging Multiple PointCloud2
Is there a way to merge two different PointCloud2 messages? Assuming they are defined in the same frame of course.
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
Is there a way to merge two different PointCloud2 messages? Assuming they are defined in the same frame of course.
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.
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?
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
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.
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
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);
does anybody translate it to python or can tell me the installation commans? I want to combine sensor_msgs/PointCloud2 from LiDAR.
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
Asked: 2013-03-19 13:10:59 -0600
Seen: 19,076 times
Last updated: Dec 13 '20
You just want to combine the points?
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.