Why are the eigen vectors not calculated as expected for cube-like point clouds with the Eigen library?

109 views Asked by At

For a project using 3d cameras, I want to calculate the oriented bounding box of a point cloud. I am using this algorithm. For general cuboids it worked well, but when testing the algorithm with a cube, the bounding box was oriented the wrong way.

I have set up a small demo project only using Point Cloud Library and Eigen like this:

pcl::PointCloud<pcl::PointXYZ> cloud;
    
// Perfect Cube - Works
cloud.points.push_back({ 10, 11, 11 });
cloud.points.push_back({ 10, 11, 10 });
cloud.points.push_back({ 10, 10, 11 });
cloud.points.push_back({ 10, 10, 10 });
cloud.points.push_back({ 11, 11, 11 });
cloud.points.push_back({ 11, 11, 10 });
cloud.points.push_back({ 11, 10, 11 });
cloud.points.push_back({ 11, 10, 10 });

// Calculate Centoid
Eigen::Vector4f centroid{};
pcl::compute3DCentroid(cloud, centroid);

Eigen::Matrix3f covariance{};
pcl::computeCovarianceMatrixNormalized(cloud, centroid, covariance);

std::cout << "Covariance:" << std::endl;
std::cout << covariance << std::endl;

const Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> solver{ covariance, Eigen::ComputeEigenvectors };
Eigen::Matrix3f eigen_vectors = solver.eigenvectors();
   
std::cout << "Eigen Vectors:" << std::endl;
std::cout << eigen_vectors << std::endl;

When adding a perfect cube to the point cloud like in the example, the algorithm works well, we get eigen vectors that are perfectly aligned to the edges of the cube ((1, 0, 0), (0, 1, 0), (0, 0, 1)). If we just change the cube a little bit (e.g. changing just the first value to 10.05), the eigen vectors are not longer aligned to the edges at all ((-0.883215, 0, -0.468968), (0.33161, 0.707107, -0.624527), (0.33161, -0.707107, -0.624527)), although the covariance matrix only changes very little. The misalignment also happens with cubes that have more than just eight points.

Do I have a mistake in my thinking here? How can I get the orientation of a cube point cloud? For other cuboids, the algorithm and eigen vector calculation works very well. I have not yet found any solution for this problem anywhere else.

Thank you for your help!

Tobi

0

There are 0 answers