简体   繁体   English

如何使用点云库查找点云的主要成分和方向

[英]how to find principal components and orientation of a point cloud using point cloud library

I have a point cloud of a wooden block. 我有一个木块的点云。 I have found the centroid of that point cloud. 我已经找到了该点云的质心。 Now I am trying to find the Principal components and orientation using point cloud library. 现在,我尝试使用点云库查找主成分和方向。 Below is the code I have tried. 以下是我尝试过的代码。 Correct me if you havent understood something. 如果您还不了解,请指正我。

        Eigen::Vector4f centroid;
        Eigen::Matrix3f covariance_matrix;

        // Extract the eigenvalues and eigenvectors
        Eigen::Vector3f eigen_values;
        Eigen::Matrix3f eigen_vectors;

        pcl::compute3DCentroid(*cloud_filtered,cluster_indices,centroid);

        // Compute the 3x3 covariance matrix
        pcl::computeCovarianceMatrix (*cloud_filtered, centroid, covariance_matrix);
        pcl::eigen33 (covariance_matrix, eigen_vectors, eigen_values);
        std::cout << "centroid-x:"<<centroid[0]<<"centroid-y:"<<centroid[1]<<"centroid-z:"<<centroid[2]<<std::endl;

If you need a rotation matrix representing an orientation, we can choose the axis in which the volume distribution of the object is highest (normalised first eigenvector - that is the eigenvector associated with the largest eigenvalue) as the first column of the matrix. 如果需要代表方向的旋转矩阵,我们可以选择对象的体积分布最高的轴(标准化的第一特征向量-与最大特征值相关的特征向量)作为矩阵的第一列。

For the 2nd column of the matrix choose the 2nd eigenvector but you have to subtract from it its projection onto the 1st eigenvector so that it is orthogonal to the first. 对于矩阵的第二列,请选择第二个特征向量,但是您必须从中减去它在第一个特征向量上的投影,以使其与第一个特征向量正交。 To calculate its projection you can use the dot product - if the eigenvectors are already normalised you can just use the dot product to calculate the length of the vector to subtract: so dot product the two vectors and multiply the 1st vector by the dot product, then subtract the resulting vector from the 1st eigenvector. 要计算其投影,您可以使用点积-如果特征向量已经归一化,则可以使用点积计算要减去的向量的长度:因此,将两个向量点积,然后将第一个向量乘以点积,然后从第一个特征向量中减去所得的向量。

For the 3rd column there will only be one choice left - the cross product of the two calculated above. 对于第三列,只剩下一个选择-上面计算出的两个乘积。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM