前景点在pcl :: MinCutSegmentation中的作用

时间:2018-03-11 00:49:06

标签: c++ computer-vision point-cloud-library point-clouds max-flow

我想了解MinCutSegmentation如何在PCL中工作。我将一些点设置为前景点,但无论我选择哪些点作为前景点,我都得到相同的结果。分段基本上是我的点云的一部分,并将剩余部分作为“前景”返回。

我在阅读MinCut论文时的理解是,我选择作为前景的点应该在最终集群中被标记为前景,但是,我发现这不会发生。以下是一些屏幕截图,用于解释正在发生的事情:

Comparator

原点云

Original point cloud

我将红框内的点设置为前景点

I am setting the points inside the red box as foreground points 分段云将这些点标记为前景,没有标记为背景的点。请注意,无论我选择什么点作为前景,我仍然得到相同的输出

另外并且可能与第一个问题相关,我不明白我在mincut算法中如何丢失一些点。我的理解是整个点云分为两部分 - 前景和背景,但在我尝试算法时似乎并非如此。有什么指针吗?

以下是我正在使用的代码段:

  //xmin,xmax,ymin,ymax represent the extremeties of the red box

  float xmin = startX - delta; 
  float xmax = startX + delta; 
  float ymin = startY - delta; 
  float ymax = startY + delta; 
  float zmin = startZ - delta; 
  float zmax = startZ + delta; 

  pcl::CropBox<pcl::PointXYZRGB> boxFilter;
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr filteredCloud (new pcl::PointCloud<pcl::PointXYZRGB>) ;
  boxFilter.setMin(Eigen::Vector4f(xmin, ymin, zmin, 0.0));
  boxFilter.setMax(Eigen::Vector4f(xmax, ymax, zmax, 0.0));
  boxFilter.setInputCloud(cloud_target);
  boxFilter.filter(*filteredCloud);
   // For this code, mode is always "mincut". 
  // I am using the crop mode to just test what points are selected by the boxfilter
  if(mode == "crop")
  {

    viewer->removePointCloud("sample cloud");
          viewer->addPointCloud<pcl::PointXYZRGB>(filteredCloud, "sample cloud");
          viewer->spinOnce(1);
  }
  else if(mode == "mincut")
  {
     pcl::IndicesPtr indices (new std::vector <int>);
     pcl::PassThrough<pcl::PointXYZRGB> pass;
     pass.setInputCloud (cloud_target);
     pass.setFilterFieldName ("z");
     pass.setFilterLimits (0.0, 1.0);
     pass.filter (*indices);

     pcl::MinCutSegmentation<pcl::PointXYZRGB> seg;
     seg.setInputCloud (cloud_target);
     seg.setIndices (indices);
     seg.setForegroundPoints (filteredCloud);

      seg.setSigma (0.15);
      seg.setRadius (10);
      seg.setNumberOfNeighbours (14);
      seg.setSourceWeight (0.3);

      std::vector <pcl::PointIndices> clusters;

      std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
      seg.extract (clusters); 
      std::chrono::steady_clock::time_point end= std::chrono::steady_clock::now();

      std::cout << "Time taken to segment = " << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() <<std::endl;



      std::cout << "Maximum flow is " << seg.getMaxFlow () << std::endl;

      pcl::PointCloud <pcl::PointXYZRGB>::Ptr colored_cloud = seg.getColoredCloud ();


      viewer->removePointCloud("sample cloud");
      viewer->addPointCloud<pcl::PointXYZRGB>(colored_cloud, "sample cloud");
      viewer->spinOnce(1);

0 个答案:

没有答案