Calculating Centroid Using Point Cloud Indices

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Calculating Centroid Using Point Cloud Indices

james
Administrator
Hi,

I am currently trying to calculate the centroid of point clusters which I have already segmented. I am having trouble doing so, encountering some errors which I am not quite sure how to resolve. I have attached the code and build information. Does anyone know how to resolve this? I have a feeling it may be because I am inputting a CloudPtr into compute3DCentroid, rather than a Cloud, but am not quite sure how to resolve this.

Thanks,
James
thesis.cpp
build.txt
Reply | Threaded
Open this post in threaded view
|

Re: Calculating Centroid Using Point Cloud Indices

faizan
This following line in your code is wrong, it has only two input parameters AFAIK

pcl::compute3DCentroid (processed_cloud2,cluster_indices, centroid);

this should be :
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
 reader.read("merged_fitpc2.pcd", *cloud);
 Eigen::Vector4f centroid;
 pcl::compute3DCentroid(*cloud,centroid);
 //cout<<new_centroid[0] << endl << new_centroid[1] << endl << new_centroid[2] << endl;

Hope this helps you.

Regards,
Faizan Shaik
Reply | Threaded
Open this post in threaded view
|

Re: Calculating Centroid Using Point Cloud Indices

james
Administrator
Hi,

Thanks very much for your reply. From my understanding of this, http://docs.pointclouds.org/trunk/group__common.html#gab36fbea084d5d20418cbbe76fba118b4, it should also be possible to use 3 parameters according to:
    [in] cloud the input point cloud
    [in] indices the point cloud indices that need to be used
    [out] centroid the output centroid

Your code, however, seems to have pointed me in the right direction, and I have changed from:
     pcl::compute3DCentroid (processed_cloud2,cluster_indices, centroid);
to:
     pcl::compute3DCentroid (*processed_cloud2, cluster_indices[i], centroid);

My code has compiled, but I do not have an OpenNI device with me currently. I eagerly await tomorrow morning to test it out.

Cheers,
James
Reply | Threaded
Open this post in threaded view
|

Re: Calculating Centroid Using Point Cloud Indices

Rupam_B
This post was updated on .
Above discussion really helps. The various signatures of the method compute3DCentroid() is available in the PCL site.

My query is:
           1. Is it still possible to calculate 3D object centroid using only the point cloud indices relevant to a particular object?

I have access to the following information:
          i) Depth image frame and corresponding color image frame.
          ii) r, g, b, d values of each pixel of the above frame.
          iii) 4 * 4 transformation matrix.
I do not have following information:
          i) PCD data corresponding to the point cloud indices (mentioned in the query)!

Thanks for any kind of help.
Reply | Threaded
Open this post in threaded view
|

Re: Calculating Centroid Using Point Cloud Indices

james
Administrator
Reply | Threaded
Open this post in threaded view
|

Re: Calculating Centroid Using Point Cloud Indices

Rupam_B
Dear James,
                  Thanks a lot for providing the link.
                  Currently, I am trying to calculate the centroid (using this code GenIndicePtr.cpp) from the indices (given in indices.txt.
                   Error is: no matching function for call to ‘compute3DCentroid(boost::shared_ptr<std::vector<int> >&, Eigen::Vector4f&)
                   How to produce a pointer of type pcl::ConstCloudIterator<PointT>& OR const pcl::PointCloud<PointT>&; so that I can use the function pcl::compute3DCentroid (*indicesptr, centroid) successfully?

Where am I doing wrong?

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: Calculating Centroid Using Point Cloud Indices

james
Administrator
Indices do not contain actual point data. They are a list of points within an already existing cloud. If you look at the documentation from the link I sent, there are no functions with the parameters you provided, as per the error you are receiving. If you want to use a subset of indices, instead of a whole cloud, you must still also call the compute3DCentroid function with the original cloud. Something like this: http://docs.pointclouds.org/trunk/group__common.html#gaef1048c26d7ee3cad4ae9436d1f4a5d6
Reply | Threaded
Open this post in threaded view
|

Re: Calculating Centroid Using Point Cloud Indices

Rupam_B
Hi,
    Thanks for your reply.
    I am using the specific signature of compute3Dcentroid(), because I DO NOT have access to the original scene point cloud data. SO, it is impossible for me to generate a pointer to the input cloud.
    So, I am curious to KNOW that is it still possible to calculate centroid by using ONLY indices. I have added a detailed question here 
    Thanks in advance for any kind of help.