I have a sparse point cloud, and I want get the dense and smoothy surface point cloud.
To convert a sparse point cloud into a dense and smooth surface point cloud, you can follow these general steps:
Preprocessing:
Surface Reconstruction:
Mesh Refinement:
Postprocessing:
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/statistical_outlier_removal.h>
#include <pcl/surface/poisson.h>
#include <pcl/surface/mls.h>
int main() {
// Load point cloud
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile("input.pcd", *cloud);
// Noise removal
pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
sor.setInputCloud(cloud);
sor.setMeanK(50);
sor.setStddevMulThresh(1.0);
sor.filter(*cloud);
// Moving Least Squares (MLS) for upsampling and smoothing
pcl::PointCloud<pcl::PointNormal>::Ptr mls_points(new pcl::PointCloud<pcl::PointNormal>);
pcl::MovingLeastSquares<pcl::PointXYZ, pcl::PointNormal> mls;
mls.setInputCloud(cloud);
mls.setSearchRadius(0.03);
mls.setPolynomialFit(true);
mls.setComputeNormals(true);
mls.process(*mls_points);
// Poisson surface reconstruction
pcl::Poisson<pcl::PointNormal> poisson;
poisson.setInputCloud(mls_points);
pcl::PolygonMesh mesh;
poisson.reconstruct(mesh);
// Save the mesh
pcl::io::savePLYFile("output.ply", mesh);
return 0;
}
import open3d as o3d
# Load point cloud
pcd = o3d.io.read_point_cloud("input.pcd")
# Noise removal
pcd, ind = pcd.remove_statistical_outlier(nb_neighbors=20, std_ratio=2.0)
# Surface reconstruction using Poisson
pcd.estimate_normals()
mesh, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(pcd, depth=9)
# Save the mesh
o3d.io.write_triangle_mesh("output.ply", mesh)
These examples demonstrate basic workflows for converting a sparse point cloud into a dense and smooth surface point cloud. You can adjust parameters and methods based on your specific requirements and the characteristics of your point cloud.