-
计算点云质心,并将其去中心化,即将点云质心设为坐标系原点
1 #pragma warning(disable:4996) 2 #include <pcl/registration/ia_ransac.h>//采样一致性 3 #include <pcl/point_types.h> 4 #include <pcl/point_cloud.h> 5 #include <pcl/features/normal_3d.h> 6 #include <pcl/features/fpfh.h> 7 #include <pcl/search/kdtree.h> 8 #include <pcl/io/pcd_io.h> 9 #include <pcl/filters/voxel_grid.h>// 10 #include <pcl/filters/filter.h>// 11 #include <pcl/registration/icp.h>//icp配准 12 #include <pcl/visualization/pcl_visualizer.h>//可视化 13 #include <time.h>//时间 14 #include <math.h> 15 #include <vector> 16 //4计算点云质心 17 Eigen::Vector4f centroid; 18 pcl::compute3DCentroid(*cloud_src, centroid); 19 std::cout << "滤波前的质心" << centroid[0] << "," << centroid[1] << "," << centroid[2] << "," << endl; 20 21 //5去中心化 22 for (size_t i = 0; i < cloud_src->points.size(); ++i) 23 { 24 cloud_src->points[i].x -= centroid[0]; 25 cloud_src->points[i].y -= centroid[1]; 26 cloud_src->points[i].z -= centroid[2]; 27 }