PCL点云光滑化

typedef pcl::PointXYZRGB PointT;
typedef pcl::PointCloud<PointT> PointCloudT;
typedef pcl::Normal PointNT;
typedef pcl::PointCloud<PointNT> PointCloudNT;
typedef pcl::PointXYZRGBNormal PointCNT;
typedef pcl::PointCloud<PointCNT> PointCloudCNT;
int main()
{
std::string fname_src = "qq0zx.pcd";


pcl::PointCloud<PointT>::Ptr cloud_src(new pcl::PointCloud<PointT>);
pcl::PointCloud<PointT>::Ptr cloud_tgt(new pcl::PointCloud<PointT>);


if (pcl::io::loadPCDFile<PointT>(fname_src, *cloud_src) == -1)
{
PCL_ERROR("Couldn't read file");
return -1;
}


pcl::search::KdTree<PointT>::Ptr tree(new pcl::search::KdTree<PointT>);
PointCloudCNT mls_points;
pcl::MovingLeastSquares<PointT, PointCNT> mls;
mls.setComputeNormals(true);
mls.setInputCloud(cloud_src);
mls.setPolynomialFit(true);
mls.setSearchMethod(tree);
mls.setSearchRadius(0.1);
mls.setPolynomialOrder(1);
mls.process(mls_points);
// 将mls后的结果xyzrgbNormal转换成为xyzrgb


cloud_tgt->points.resize(mls_points.size());
for (size_t i = 0; i < mls_points.size(); ++i)
{
cloud_tgt->points[i].x = mls_points.points[i].x;
cloud_tgt->points[i].y = mls_points.points[i].y;
cloud_tgt->points[i].z = mls_points.points[i].z;
cloud_tgt->points[i].r = mls_points.points[i].r;
cloud_tgt->points[i].g = mls_points.points[i].g;
cloud_tgt->points[i].b = mls_points.points[i].b;
}
cloud_tgt->width = mls_points.size();
cloud_tgt->height = 1;
//pcl::io::savePCDFile("qq0p.pcd", *cloud_tgt);
pcl::io::savePCDFileASCII("qq0p.pcd", *cloud_tgt);
pcl::visualization::PCLVisualizer viewer1;
viewer1.setBackgroundColor(255, 255, 255);
viewer1.addPointCloud(cloud_src);
while (!viewer1.wasStopped())
{   //user_data++;
viewer1.spinOnce();


}
pcl::visualization::PCLVisualizer viewer2;
viewer2.setBackgroundColor(255, 255, 255);
viewer2.addPointCloud(cloud_tgt);
while (!viewer2.wasStopped())
{   //user_data++;
viewer2.spinOnce();


}
system("pause");
return (0);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值