PCL 点云库 点云 凸包检测 Convex Hull 凸包顶点求解

点云凸包检测还是比较常用的,PCL自带的凸包检测 ConvexHull ,这个函数比较简单,设置凸包维度 setDimension即可,在这里记录一下

头文件:#include <pcl/surface/convex_hull.h>

	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::io::loadPCDFile<pcl::PointXYZ>("bun_45.pcd", *cloud);

	pcl::ConvexHull<pcl::PointXYZ> hull;                  
	hull.setInputCloud(cloud);                   
	hull.setDimension(3);

	std::vector<pcl::Vertices> polygons;                 
	pcl::PointCloud<pcl::PointXYZ>::Ptr surface_hull(new pcl::PointCloud<pcl::PointXYZ>);
	hull.reconstruct(*surface_hull, polygons);           

	cout << surface_hull->size() << endl;

	// ---------------------- Visualizer -------------------------------------------
	boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer);
	viewer->setBackgroundColor(255,255,255);

	pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> color_handler(cloud, 255, 255, 0);
	viewer->addPointCloud(cloud, color_handler, "sample cloud");
	viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 6, "sample cloud");

	pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> color_handlerK(surface_hull, 255, 0, 0);
	viewer->addPointCloud(surface_hull, color_handlerK, "point");
	viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 6, "point");

	//viewer->addPolygon<pcl::PointXYZ>(surface_hull, 0, 0, 255, "polyline");

	while (!viewer->wasStopped())
	{
		viewer->spinOnce(100);
	}

采用斯坦福小兔点云,效果如图:

如果进一步将某个确定的凸包中的点云从场景分割出来,可以采用 CropHull 进行滤波

CropHull 滤波可以参考:https://blog.csdn.net/zfjBIT/article/details/92795689

感谢肖蜗牛的指正,如果得到凸包曲线,还需要进一步三角化,仅仅把凸包点连起来是不正确的

  • 5
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值