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
Add a comment  | 

2 Answers 2

Reset to default 1

pcl::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