ProjectInliers投影滤波实现

该代码实现了一个将点云数据投影到平面上的算法。通过输入点云、投影后的点云和平面方程系数,利用投影公式计算每个点的新坐标,并存储到投影点云中。该过程对于三维点云处理和可视化具有重要意义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实现:以平面模型投影为例在这里插入图片描述

/**
 * @description:			点云投影
 * @param cloud				输入点云
 * @param cloud_projected	投影点云
 * @param coefficients		投影平面方程系数
 */
void projection(pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud, pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud_projected, pcl::ModelCoefficients::Ptr coefficients)
{
	float a = coefficients->values[0], b = coefficients->values[1], c = coefficients->values[2], d = coefficients->values[3];
	for (size_t i = 0; i < cloud->points.size(); ++i)
	{
		float x0 = cloud->points[i].x;
		float y0 = cloud->points[i].y;
		float z0 = cloud->points[i].z;
		float xp = ((b*b + c*c)*x0 - a*(b*y0 + c*z0 + d)) / (a*a + b*b + c*c);
		float yp = ((a*a + c*c)*y0 - b*(a*x0 + c*z0 + d)) / (a*a + b*b + c*c);
		float zp = ((a*a + b*b)*z0 - c*(a*x0 + b*y0 + d)) / (a*a + b*b + c*c);
		cloud_projected->push_back(pcl::PointXYZ(xp, yp, zp));
	}
}

代码传送门:https://github.com/taifyang/PCL-algorithm

// 投影滤波器 void MainWindow::doActionPCLProjectInliers() { if (getSelectedEntities().size() != 1) { ccLog::Print(QStringLiteral("只能选择一个点云实体")); return; } ccHObject* entity = getSelectedEntities()[0]; ccPointCloud* ccCloud = ccHObjectCaster::ToPointCloud(entity); // ---------------------------读取数据到PCL---------------------------------- pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); cloud->resize(ccCloud->size()); for (int i = 0; i < cloud->size(); ++i) { const CCVector3* point = ccCloud->getPoint(i); cloud->points[i].x = point->x; cloud->points[i].y = point->y; cloud->points[i].z = point->z; } // -----------------------------对话框--------------------------------------- float radius = QInputDialog::getDouble(this, QStringLiteral("参数设置"), QStringLiteral("搜索半径: "), 0.1, 0, 100, 4); // ----------------------------投影滤波器-------------------------------------- //创建 x+y+z=0 平面 pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients()); coefficients->values.resize(4); //设置模型系数的大小 coefficients->values[0] = 1.0; //x系数 coefficients->values[1] = 1.0; //y系数 coefficients->values[2] = 1.0; //z系数 coefficients->values[3] = 0.0; //常数项 //投影滤波 pcl::PointCloud<pcl::PointXYZ>::Ptr filtered(new pcl::PointCloud<pcl::PointXYZ>); pcl::ProjectInliers<pcl::PointXYZ> us; us.setModelType(pcl::SACMODEL_PLANE); //设置对象对应的投影模型 us.setInputCloud(cloud); //设置输入点云 us.setModelCoefficients(coefficients);//设置模型对应的系数 us.filter(*filtered); // ------------------------PCL->CloudCompare-------------------------------- if (!filtered->empty()) { ccPointCloud* newPointCloud = new ccPointCloud(QString("ProjectInliers")); for (int i = 0; i < filtered->size(); ++i) { double x = filtered->points[i].x; double y = filtered->points[i].y; double z = filtered->points[i].z; newPointCloud->addPoint(CCVector3(x, y, z)); } newPointCloud->setRGBColor(ccColor::Rgba(255, 255, 255, 255)); newPointCloud->showColors(true); if (ccCloud->getParent()) { ccCloud->getParent()->addChild(newPointCloud); } ccCloud->setEnabled(false); addToDB(newPointCloud); refreshAll(); updateUI(); } else { ccCloud->setEnabled(true); // Display a warning message in the console dispToConsole("Warning: example shouldn't be used as is", ccMainAppInterface::WRN_CONSOLE_MESSAGE); } } 提供代码绘制的关键函数关系图,图中使用中文注释关键步骤和函数调用关系
最新发布
07-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

给算法爸爸上香

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值