基于 RANSAC 及其改进的面片分割

基于 RANSAC 及其改进的面片分割_第1张图片

 ​​​​基于 RANSAC 及其改进的面片分割_第2张图片

 基于 RANSAC 及其改进的面片分割_第3张图片

 基于 RANSAC 及其改进的面片分割_第4张图片

 基于 RANSAC 及其改进的面片分割_第5张图片

 源代码展示:

//经典ransac
void main01()
{
	IO IOexample;
	RANSAC RANSACExample;
	EuclideanCluster RGExample;

	char *inputpath = "..\\testdata.xyz";
	char *outpath = "..\\testdata_ransac.txt";

	clock_t start, finish;
	start = clock();
	vector cloud = IOexample.ReadPointXYZIntoVector(inputpath);//读入点云数据
	if (cloud.size() == 0)
	{
		cout << "文件输入路径有问题" << endl;
		system("pause");
	}

	//(1)进行单栋分离
	std::vector> multiple_buildings;
	double r = 2.0;
	multiple_buildings = RGExample.EuclideanCluster2DDis(cloud, r);
	//(2)对每栋建筑物进行ransac探测面片
	ofstream outfile(outpath, ios::out);
	srand((int)time(0));
	int sumplanes = 0;
	for (int i = 0; i < multiple_buildings.size(); i++)
	{
		cout << "开始处理第" << i << "栋建筑物" << endl;
		double DisThres = 0.1;
		int iterativeTimes = 400;

		vector> clusters;
		clusters = RANSACExample.RANSACDistance(multiple_buildings[i], DisThres, iterativeTimes);
		for (int j = 0; j < clusters.size(); j++)
		{
			if (clusters[j].size() > 5)//只输出多于5个点的面片
			{
				double r = rand() % 255;
				double g = rand() % 255;
				double b = rand() % 255;

				for (int k = 0; k < clusters[j].size(); k++)
				{
					outfile << fixed << setprecision(3) << clusters[j][k].x << "\t" << clusters[j][k].y << "\t" << clusters[j][k].z << "\t" << fixed << setprecision(0) << r << '\t' << g << "\t" << b << endl;
				}
			}
		}
	}
	cout << "结束" << endl;
	system("pause");


}

基于 RANSAC 及其改进的面片分割_第6张图片

 

基于C++的源代码下载地址:https://download.csdn.net/download/qq_32867925/87163059

你可能感兴趣的:(PCL数据处理,ransac,平面分割,点云)