PCL European Clustering

1. Clustering

Detailed explanation of European clustering (point cloud data processing) - JAT0929's Blog - CSDN Blog

That's probably what it means.

2. European clustering

PCL: European Clustering Segmentation_Monkey King's Blog-CSDN Blog

using namespace std;

typedef pcl::PointXYZRGB PointT;
int main()
{
	std::string filename = "C:\\Users\\Albert\\Desktop\\DATA\\trees.pcd";
	pcl::PointCloud<pcl::PointXYZRGB>::Ptr  cloud(new pcl::PointCloud<pcl::PointXYZRGB>());
	if (pcl::io::loadPCDFile<pcl::PointXYZRGB>(filename, *cloud) == -1) //* 读入PCD格式的文件,如果文件不存在,返回-1
	{
		PCL_ERROR("Couldn't read file test_pcd.pcd \n"); //文件不存在时,返回错误,终止程序。
		return (-1);
	}
	cout << " 点云大小:  " << cloud->size() << endl;



	//  欧式聚类 
	pcl::search::KdTree<pcl::PointXYZRGB>::Ptr tree(new  pcl::search::KdTree<pcl::PointXYZRGB>());
	pcl::EuclideanClusterExtraction<pcl::PointXYZRGB> ece;// 欧式聚类
	ece.setInputCloud(cloud);
	ece.setClusterTolerance(0.5);   // 设置近邻的搜索半径
	ece.setMinClusterSize(1000);  // 设置最小的聚类点数
	ece.setMaxClusterSize(1000000);  // 设置最大的聚类点云点数
	ece.setSearchMethod(tree);   
	vector<pcl::PointIndices> cluster_indices;
	ece.extract(cluster_indices);  // 输出点云的聚类别

	pcl::PCDWriter writer;
	int j = 0;
	for (vector<pcl::PointIndices>::const_iterator it = cluster_indices.begin(); it != cluster_indices.end();++it)
	{
		pcl::PointCloud<PointT>::Ptr cloud_cluster(new pcl::PointCloud<PointT>);

		for (vector<int>::const_iterator pit = it->indices.begin(); pit != it->indices.end(); pit++)
			cloud_cluster->points.push_back(cloud->points[*pit]);

		stringstream ss;
		ss << "" << j + 1 << ".pcd";
		writer.write<pcl::PointXYZRGB>(ss.str(),*cloud_cluster,true);
		j++;

	}

	system("pause");
	return  0;
}

 PCL Tutorial - European Clustering Segmentation of Point Cloud Segmentation_pcl European Clustering_SOC Luo Sanpao's Blog-CSDN Blog

Guess you like

Origin blog.csdn.net/weixin_39354845/article/details/130122937