PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.86k stars 4.61k forks source link

use EuclideanClusterExtraction for FPFH descriptors #3111

Open XuankeShi opened 5 years ago

XuankeShi commented 5 years ago

i've try enclideadClusterExtraction for fpfh for each point, but it did't work,is there anyone who has tried it ,i need your help. thx very much.And i wanna get the result as follows: Surfaces with the same geometric features come together。

XuankeShi commented 5 years ago

i've try enclideadClusterExtraction for fpfh for each point, but it did't work,is there anyone who has tried it ,i need your help. thx very much.

The code is as follows:

include

include <pcl/io/pcd_io.h>

include <pcl/visualization/pcl_visualizer.h>

include <pcl/point_types.h>

include <pcl/features/normal_3d_omp.h>

include <pcl/segmentation/extract_clusters.h>

include <pcl/kdtree/kdtree.h>

include <pcl/filters/extract_indices.h>

include <pcl/filters/voxel_grid.h>

include <pcl/features/fpfh.h>

include <pcl/features/pfh.h>

include <pcl/segmentation/impl/extract_clusters.hpp>

include <pcl/search/impl/search.hpp>

double computeCloudResolution(const pcl::PointCloud::ConstPtr& cloud) { double resolution = 0.0; int numberOfPoints = 0; int nres; std::vector indices(2); std::vector squaredDistances(2); pcl::search::KdTree tree; tree.setInputCloud(cloud);

for (size_t i = 0; i < cloud->size(); ++i)
{
    if (!pcl_isfinite((*cloud)[i].x))
        continue;

    // Considering the second neighbor since the first is the point itself.
    nres = tree.nearestKSearch(i, 2, indices, squaredDistances);
    if (nres == 2)
    {
        resolution += sqrt(squaredDistances[1]);
        ++numberOfPoints;
    }
}
if (numberOfPoints != 0)
    resolution /= numberOfPoints;

return resolution;

}

int main(int argc, char *argv) { pcl::PointCloud::Ptr scene(new pcl::PointCloud()); pcl::PointCloud::Ptr normals(new pcl::PointCloud()); pcl::PointCloud::Ptr fpfhs(new pcl::PointCloud()); if (pcl::io::loadPCDFile("milk_cartoon_all_small_clorox.pcd",scene) == -1) { PCL_ERROR("can't open the pcd file "); system("pause "); return -1; }

double resolution = 2*computeCloudResolution(scene);
pcl::VoxelGrid<pcl::PointXYZ> vg;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
vg.setInputCloud(scene);
vg.setLeafSize(resolution, resolution, resolution);
vg.filter(*cloud_filtered);
std::cout << "PointCloud after filtering has: " << cloud_filtered->points.size() << " data points." << std::endl; 
pcl::search::KdTree<pcl::PointXYZ>::Ptr kdtree(new pcl::search::KdTree<pcl::PointXYZ>());
kdtree->setInputCloud(cloud_filtered);
pcl::NormalEstimationOMP<pcl::PointXYZ, pcl::Normal> ne;
ne.setNumberOfThreads(3);
ne.setInputCloud(cloud_filtered);
ne.setSearchMethod(kdtree);
ne.setRadiusSearch(5 * resolution);
ne.setViewPoint(0,0,0);
ne.compute(*normals);

pcl::FPFHEstimation<pcl::PointXYZ, pcl::Normal, pcl::FPFHSignature33> fpfh;
fpfh.setInputCloud(cloud_filtered);
fpfh.setInputNormals(normals);
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>());
fpfh.setSearchMethod(tree);
fpfh.compute(*fpfhs);

//std::vector<pcl::PointIndices> cluster_indices;
std::vector<pcl::PointIndices> cluster_indices;
pcl::EuclideanClusterExtraction<pcl::FPFHSignature33> ec;
ec.setClusterTolerance(10000);
ec.setMinClusterSize(50);
ec.setMaxClusterSize(200000);
pcl::search::KdTree<pcl::FPFHSignature33>::Ptr kdtree2(new pcl::search::KdTree<pcl::FPFHSignature33>);
kdtree2->setInputCloud(fpfhs);
ec.setSearchMethod(kdtree2);
ec.setInputCloud(fpfhs);
ec.extract(cluster_indices);

}

stale[bot] commented 4 years ago

Marking this as stale due to 30 days of inactivity. It will be closed in 7 days if no further activity occurs.