【编程实践】利用Alpha Shape凹包提取三维点云某个投影下的边界

1 程序执行结果

实现效果:白色的为提取的点云边界(体素下采样叶节点参数setLeafSize(0.1f,0.1f,0.1f),投影至Z=0平面,concave hull参数为0.3)
在这里插入图片描述
在这里插入图片描述
实现效果:白色的为提取的点云边界(体素下采样叶节点参数setLeafSize(0.1f,0.1f,0.1f),投影至Z=-1.0平面,concave hull参数为0.7)
在这里插入图片描述
在这里插入图片描述

2 代码实现

// alpha-concave hull
#include <pcl/io/pcd_io.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/surface/concave_hull.h>
#include <pcl/console/time.h>
using namespace std;

typedef pcl::PointXYZ PointT; //C++类型定义,用于简化类型名称
typedef pcl::PointCloud<PointT> PointCloudT;

int main()
{
	cout << "Start..." << endl;
	PointCloudT::Ptr cloud(new PointCloudT);
	string path = ".\\input\\Kuangshan_long_R.pcd";

	if (pcl::io::loadPCDFile(path, *cloud) < 0)
	{
		PCL_ERROR("The point cloud file does not exist.\n");
		return -1;
	}
	cout << "There are " << cloud->points.size() << " points of data." << endl;
	//--------------------------点云数据下采样 --------------------------
	PointCloudT::Ptr cloud_sub(new PointCloudT);	//下采样点云
	pcl::VoxelGrid<PointT> vg;			//创建体素下采样对象
	vg.setInputCloud(cloud);			//设置下采样输入点云
	vg.setLeafSize(0.1f, 0.1f, 0.1f);//设置体素栅格边长
	vg.filter(*cloud_sub);			//执行体素下采样
	//利用遍历修改某维度值的方法进行投影
	for (size_t i = 0; i < cloud_sub->size(); ++i)
	{
		cloud_sub->points[i].z = 0.0f;//投影至Z=0平面
	}
	//-------------------- AlphaShapes提取投影边界 凹包算法(ConcaveHull)--------------------
	pcl::console::TicToc time;
	time.tic();

	PointCloudT::Ptr cloud_boundary(new PointCloudT);
	pcl::ConcaveHull<PointT> ch;
	ch.setInputCloud(cloud_sub);
	ch.setAlpha(0.3);
	ch.reconstruct(*cloud_boundary);
	cout << "This operation takes :" << time.toc() / 1000 << " s(second)" << endl;
	//---------------------------- 保存边界点云 --------------------------
	if (!cloud_boundary->empty())
	{
		pcl::io::savePCDFileBinary(".\\output\\0911\\boundary_points.pcd", *cloud_boundary);
		cout << "There are a total of " << cloud_boundary->points.size() << " points in the boundary point cloud." << endl;
	}
	else
	{
		PCL_ERROR("The boundary point cloud is empty. \a\n");
		system("pause");
		return -1;
	}
	cout << "Done!" << endl;
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值