重心一般有可能在点云外
这里发个求点云中心的。
vector<double> xyz_means(pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud)
{
double mean_x, mean_y, mean_z; //点云均值
double stddev_x, stddev_y, stddev_z; //点云标准差
vector<float> vec_x, vec_y, vec_z;
for (size_t i = 0; i < cloud->points.size(); i++)
{
vec_x.push_back(cloud->points[i].x);
vec_y.push_back(cloud->points[i].y);
vec_z.push_back(cloud->points[i].z);
}
pcl::getMeanStd(vec_x, mean_x, stddev_x);
pcl::getMeanStd(vec_y, mean_y, stddev_y);
pcl::getMeanStd(vec_z, mean_z, stddev_z);
//cout << "\n->点云X坐标的均值为:" << endl;
//cout << mean_x << endl;
vector<double> xyz_mean;
xyz_mean.push_back(vec_x);
cout << "\n->点云X坐标的标准差为:" << endl;
//cout << stddev << endl;
}