PCL 的主成分分析

Principal component analysis on PCL

我正在使用 PCL 和 C++,并希望在已经聚类的点云(即在每个单独的聚类上)上执行 PCA。这个想法是通过沿着特征向量测量它们的大小来消除所有太 large/small 的簇。所以预期的算法是:获取每个集群的特征向量,将集群点投影到相应的特征向量上,以测量点沿这些维度的最大距离,并从那里消除具有 "bad" dimensions/ratio 的所有集群方面。我在实施时遇到困难。您能提供的帮助越多,您就越开心。这就是我的数据的组织方式(为了清楚起见,这些是片段,cluster_indices 已经被正确提取并经过检查),以及我开始的内容:

std::vector<pcl::PointIndices> cluster_indices;
pcl::PCA<pcl::PointXYZ> cpca = new pcl::PCA<pcl::PointXYZ>;
cpca.setInputCloud(input);
Eigen::Vector3f pca_vector(3,3);
// and now iterating with a for loop over the clusters, but having issues using setIndices already
for (std::vector<pcl::PointIndices>::const_iterator it = cluster_indices.begin (); it != cluster_indices.end (); ++it, n++)
{
    cpca.setIndices(it->indices); //not sure what to put in brackets, everything I thought of returns an error!
    pca_vector = cpca.getEigenVectors();
}

这似乎是一个普遍的问题。所以我找到了这个解决方案: 不要使用指针进行迭代,而是使用常规迭代器,然后使用这些公式。 PointIndicesPtr pi_ptr(new PointIndices); pi_ptr->指数=cluster_indices[i].指数; //现在可以使用pi_ptr作为输入