Bruce
Bruce

Reputation: 445

Keep custom fields during supervoxel clustering process in Point Cloud Library (PCL)

I am new at PCL (Point Cloud Library), and I was trying to implement supervoxel_clustering (this link) on my custom dataset. My point clouds dataset has these fields: X Y Z R G B L1 L2 where R, G, B are integer values between 0-255 and L1 and L2 are integer labels.

After applying supervoxel, I save the point clouds with their labels:

/// save the labeled cloud 
PointLCloudT::Ptr labeled_cloud = super.getLabeledCloud(); 
pcl::io::savePCDFileASCII("/path/labeled_cloud.pcd", *labeled_cloud);

My question is: how to transfer my labels and colors from original point clouds during the process. I try to define my own point type, something like: X Y Z R G B L1 L2 L3, but with the tutorial on point types it is not trivial to do that. One dummy solution I am thinking of, is using KD-tree and transfer labels from supervoxel result to the original points, but still I need to read my original points with all custom fields in pcl.

Anyone can help me with this?

Thanks, Bruce

Upvotes: 1

Views: 604

Answers (1)

Rooscannon
Rooscannon

Reputation: 316

I understand you have already defined a point type with L1 and L2 fields.

The points come out from supervoxel_clustering in the same order as they were put in and the getLabeledCloud() method returns all the original points. The easiest solution is to define the point cloud with L1, L2 and L3 fields and copy your original point cloud to that type and then iterate over the cloud and copy the label from labeled_cloud.

something like

pcl::PointCloud<your_custom_point_type_with_L1_L2_L3> combined_cloud;
pcl::copyPointCloud( original_cloud, combined_cloud );

for ( int i = 0; i < labeled_cloud->point.size(); i++ ){
    combined_cloud[i].label3 = labeled_cloud[i].label;
}

Upvotes: 1

Related Questions