admin管理员组文章数量:1125973
I have a las file:
The data points in this las file are not evenly spaced. It is a point cloud, as you can see from zooming in:
As an exercise, I would like to try interpolating this data using a regularly spaced 2D grid. I'm not too concerned for now that the las file is a triangle shape.
In some sense, I'm trying to turn this point cloud into a 2D image with regularly spaced pixels.
My first cut at the problem was to try using point cloud library.
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/surface/grid_projection.h>
#include <pcl/io/pcd_io.h>
#include <pcl/filters/approximate_voxel_grid.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/io/ply_io.h>
using namespace pcl::io;
int main(int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
if (pcl::io::loadPCDFile("/app/data/triangle.pcd", *cloud) == -1)
{
PCL_ERROR("Couldn't read file\n");
return (-1);
}
pcl::VoxelGrid<pcl::PointXYZ> sor;
sor.setInputCloud (cloud);
sor.setLeafSize (1, 1, 1);
sor.filter (*cloud_filtered);
pcl::io::savePCDFileASCII("/app/output/interpolated_cloud.pcd", *cloud_filtered);
return 0;
}
This doesn't seem to have performed the interpolation at regularly spaced intervals
It appears the VoxelGrid has performed downsampling but not at regular intervals. I also had to use PDAL to convert my las file to a PCD file
{
"pipeline":
[
{
"type": "readers.las",
"filename": "./data/triangle.las"
},
{
"type": "writers.pcd",
"filename": "./data/triangle.pcd"
}
]
}
Perhaps I am going in completely the wrong direction here. Maybe I have to implement my own solution.
I have a las file:
The data points in this las file are not evenly spaced. It is a point cloud, as you can see from zooming in:
As an exercise, I would like to try interpolating this data using a regularly spaced 2D grid. I'm not too concerned for now that the las file is a triangle shape.
In some sense, I'm trying to turn this point cloud into a 2D image with regularly spaced pixels.
My first cut at the problem was to try using point cloud library.
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/surface/grid_projection.h>
#include <pcl/io/pcd_io.h>
#include <pcl/filters/approximate_voxel_grid.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/io/ply_io.h>
using namespace pcl::io;
int main(int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
if (pcl::io::loadPCDFile("/app/data/triangle.pcd", *cloud) == -1)
{
PCL_ERROR("Couldn't read file\n");
return (-1);
}
pcl::VoxelGrid<pcl::PointXYZ> sor;
sor.setInputCloud (cloud);
sor.setLeafSize (1, 1, 1);
sor.filter (*cloud_filtered);
pcl::io::savePCDFileASCII("/app/output/interpolated_cloud.pcd", *cloud_filtered);
return 0;
}
This doesn't seem to have performed the interpolation at regularly spaced intervals
It appears the VoxelGrid has performed downsampling but not at regular intervals. I also had to use PDAL to convert my las file to a PCD file
{
"pipeline":
[
{
"type": "readers.las",
"filename": "./data/triangle.las"
},
{
"type": "writers.pcd",
"filename": "./data/triangle.pcd"
}
]
}
Perhaps I am going in completely the wrong direction here. Maybe I have to implement my own solution.
Share Improve this question edited yesterday Christoph Rackwitz 15.2k5 gold badges38 silver badges49 bronze badges asked Jan 9 at 2:51 savsav 2,1525 gold badges25 silver badges48 bronze badges 3- I'm not sure what your second image is showing us. If those are the points that will be used as interpolation sources, then it seems reasonable. – Tim Roberts Commented Jan 9 at 3:04
- @TimRoberts Yes that is correct – sav Commented Jan 9 at 4:13
- I'm not actually sure if PCL supports the feature I want – sav Commented Jan 9 at 4:36
2 Answers
Reset to default 1pcl::VoxelGrid does something different from what you described. Firstly, it treats all three dimensions the same, while you rather want to treat it as 2D with a "special" third dimension. Secondly, VoxelGrid does use a regularly spaced 3D grid, but the points inside each voxel are represented in the output by the mean of these points, which then does not necessarily appear regularly spaced any more (see also https://pointclouds.org/documentation/classpcl_1_1_voxel_grid.html#details ). And thirdly, VoxelGrid will not fill empty voxels, even if these are in the middle of other data (in different words, it does not do interpolation in the sense you want to).
I think the closest that PCL has to what you want to do is MovingLeastSquares, maybe with an upsampling of the points (see https://pointclouds.org/documentation/classpcl_1_1_moving_least_squares.html ). But I am still not sure if that is 100% what you want.
In case you decide to implement this yourself, here are some ideas: For each point on the 2D grid/raster, search for neighbours in your original point cloud (I would go with knn search, not points-within-radius search). Next, decide whether the neighbours are close enough to do a valid interpolation (extrapolation will likely fail if too far away). Finally, fit a polynomial to the neighbours, and evaluate at the 2D grid point. You could have a look at the MovingLeastSquares code for this step.
I tried using lidR in R
installing packages
install.packages("lidR")
install.packages("gstat")
library(lidR)
Interpolation
las <- readLAS("triangle.las")
dem <- rasterize_terrain(las, res = 1, algorithm = knnidw(k = 10, p = 2), use_class = c(0L,0L))
plot(dem)
plot_dtm3d(dem, bg = "white")
These look like they are regularly spaced
And can be drawn as an image
本文标签: cInterpolation of Point cloud at regular intervalsStack Overflow
版权声明:本文标题:c++ - Interpolation of Point cloud at regular intervals - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736676106a1947189.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论