c++ - Region growing segmentation clusters are wrong? -


i performing region growing segmentation of point cloud have of room via pcl point cloud library. colored cloud looks following: colored cloud

as can see of clusters according surface. however, when show each cluster separatedly, these of results: results 1

results 2

clearly clusters not same in colored cloud, dont understand why. using code store clusters separated point clouds:

//store clusters new pcls , clusters in array of pcls      std::vector<pcl::pointcloud<pcl::pointxyzrgb>::ptr> clusters_pcl;      (int = 0; < clusters.size(); ++i) {              pcl::pointcloud<pcl::pointxyzrgb>::ptr cloud_cluster(                              new pcl::pointcloud<pcl::pointxyzrgb>);              cloud_cluster->width = clusters[i].indices.size();              cloud_cluster->height = 1;              cloud_cluster->is_dense = true;              (int j = 0; j < clusters[i].indices.size(); ++j) {                      //take corresponding point of filtered cloud indices new pcl                      cloud_cluster->push_back(                                      point_cloud_ptr->at(clusters[i].indices[j]));              }              indices2.clear();              //pcl::removenanfrompointcloud(*cloud_cluster, *cloud_cluster, indices2);              clusters_pcl.push_back(cloud_cluster);      }  

is code doing wrong or output of region growing segmentation right?

cheers

-------------edit-----------------

here point cloud using tests.

here complete region growing segmentation code, similar 1 in tutorial:

std::vector<pcl::pointcloud<pcl::pointxyzrgb>::ptr> region_growing_segmentation(     pcl::pointcloud<pcl::pointxyzrgb>::ptr point_cloud_ptr) { pcl::pointcloud<pcl::pointxyzrgb>& point_cloud = *point_cloud_ptr; std::vector<int> indices2; // create filtering object: downsample dataset using leaf size of 1cm pcl::voxelgrid<pcl::pointxyzrgb> vg; pcl::pointcloud<pcl::pointxyzrgb>::ptr cloud_filtered(         new pcl::pointcloud<pcl::pointxyzrgb>); vg.setinputcloud(point_cloud_ptr); vg.setleafsize(0.025f, 0.025f, 0.025f); vg.filter(*cloud_filtered); std::cout << "pointcloud after filtering has: "         << cloud_filtered->points.size() << " data points." << std::endl;  pcl::search::search<pcl::pointxyzrgb>::ptr tree = boost::shared_ptr<         pcl::search::search<pcl::pointxyzrgb> >(         new pcl::search::kdtree<pcl::pointxyzrgb>); pcl::pointcloud<pcl::normal>::ptr normals(new pcl::pointcloud<pcl::normal>); pcl::normalestimation<pcl::pointxyzrgb, pcl::normal> normal_estimator; normal_estimator.setsearchmethod(tree); normal_estimator.setinputcloud(cloud_filtered); normal_estimator.setksearch(50); normal_estimator.compute(*normals);  pcl::regiongrowing<pcl::pointxyzrgb, pcl::normal> reg; reg.setminclustersize(50); reg.setmaxclustersize(1000000); reg.setsearchmethod(tree); reg.setnumberofneighbours(100); reg.setinputcloud(cloud_filtered); reg.setinputnormals(normals); reg.setsmoothnessthreshold(5.0 / 180.0 * m_pi); reg.setcurvaturethreshold(1);  std::vector<pcl::pointindices> clusters; reg.extract(clusters); pcl::pointcloud<pcl::pointxyzrgb>::ptr colored_cloud =         reg.getcoloredcloud(); pcl::visualization::cloudviewer viewer("cluster viewer"); viewer.showcloud(colored_cloud); while (!viewer.wasstopped()) { } std::vector<pcl::pointcloud<pcl::pointxyzrgb>::ptr> clusters_pcl;  (int = 0; < clusters.size(); ++i) {  pcl::pointcloud<pcl::pointxyzrgb>::ptr cloud_cluster(  new pcl::pointcloud<pcl::pointxyzrgb>);  cloud_cluster->width = clusters[i].indices.size();  cloud_cluster->height = 1;  cloud_cluster->is_dense = true;  (int j = 0; j < clusters[i].indices.size(); ++j) {  //take corresponding point of filtered cloud indices new pcl  cloud_cluster->push_back(  point_cloud_ptr->at(clusters[i].indices[j]));  }  indices2.clear();  //pcl::removenanfrompointcloud(*cloud_cluster, *cloud_cluster, indices2);  clusters_pcl.push_back(cloud_cluster);  }  return clusters_pcl; } 

try code:

    pcl::extractindices<pcl::pointxyzrgb> extract;     std::vector<pcl::pointcloud<pcl::pointxyzrgb>::ptr> output_clouds;  //vector of point clouds hold cluster clouds      (int = 0; < clusters.size(); ++i){         upcloud cloud_temp(new pcl::pointcloud<pcl::pointxyzrgb>);          //extract cloud cluster indicies         extract.setinputcloud(input_cloud);         pcl::pointindices cluster = clusters[i];         boost::shared_ptr<pcl::pointindices> indicies = boost::make_shared<pcl::pointindices>(cluster);         extract.setindices(indicies);         extract.setnegative(false);         extract.filter(*cloud_temp);          output_clouds.push_back(cloud_temp);     } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -