1

I want to get the centroid of point cloud data based on color using kinect v2. Even after searching for a long time I was not able to find a package which can do this task. But since this is a general problem, I think there should be a existing package.

Please help. Thanks in advance!

vacky
  • 277
  • 1
  • 4
  • 16

1 Answers1

2

If you are using PCL you can do

pcl::PointXYZRGB centroid;
pcl::computeCentroid(*cloud, centroid);

Otherwise it is just the average of the points. For example:

                pcl::PointXYZI centroid;

                float x = 0, y = 0, z = 0;
                for (int k = 0; k < cloud->size(); k++)
                {
                   x += cloud->at(k).x;
                   y += cloud->at(k).y;
                   z += cloud->at(k).z;
                }
                centroid.x = x / (cloud->size() + 0.0);
                centroid.y = y / (cloud->size() + 0.0);
                centroid.z = z / (cloud->size() + 0.0);
brad
  • 930
  • 9
  • 22