点云凸包检测还是比较常用的,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
感谢肖蜗牛的指正,如果得到凸包曲线,还需要进一步三角化,仅仅把凸包点连起来是不正确的