效果:
代码:
- #include
- #include
- #include
-
- #include
- #include
- #include
- #include
- #include
- #include
// for pcl::removeNaNFromPointCloud - #include
-
- using namespace std::chrono_literals;
-
- int main()
- {
- pcl::search::Search
::Ptr tree (new pcl::search::KdTree) ; -
- pcl::PointCloud
::Ptr cloud(new pcl::PointCloud) ; - if( pcl::io::loadPCDFile
("region_growing_rgb_tutorial.pcd", *cloud) == -1) - {
- std::cout << "cloud reading failed." << std::endl;
- return (-1);
- }
-
- pcl::IndicesPtr indices (new std::vector<int>);
- pcl::removeNaNFromPointCloud(*cloud, *indices); //从点云中移除包含NaN值的点,并返回非NaN点的索引
-
- pcl::RegionGrowingRGB
reg; - reg.setInputCloud(cloud);
- reg.setIndices(indices);
- reg.setSearchMethod(tree);
- reg.setDistanceThreshold(10);
- reg.setPointColorThreshold(6);
- reg.setRegionColorThreshold(5);
- reg.setMinClusterSize(600);
-
- std::vector
clusters; - reg.extract(clusters);
-
-
- pcl::PointCloud
::Ptr colored_cloud = reg.getColoredCloud(); - pcl::visualization::CloudViewer viewer("cluster viewer");
- viewer.showCloud(colored_cloud);
- while (!viewer.wasStopped()) {
- std::this_thread::sleep_for(100);
- }
-
- return(0);
-
- }