【PCL】(二十五)基于Min-Cut的点云分割

Min-Cut Based Segmentation

提出这个方法的论文:Min-Cut Based Segmentation of Point Clouds

最大流最小割问题


min_cut_segmentation.cpp

cpp 复制代码
#include <iostream>
#include <vector>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/filters/filter_indices.h> // for pcl::removeNaNFromPointCloud
#include <pcl/segmentation/min_cut_segmentation.h>

int main ()
{
      pcl::PointCloud <pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud <pcl::PointXYZ>);
      if ( pcl::io::loadPCDFile <pcl::PointXYZ> ("min_cut_segmentation_tutorial.pcd", *cloud) == -1 )
      {
            std::cout << "Cloud reading failed." << std::endl;
            return (-1);
      }
      // 仅选择有效点进行分割
      pcl::IndicesPtr indices (new std::vector <int>);
      pcl::removeNaNFromPointCloud(*cloud, *indices);

      pcl::MinCutSegmentation<pcl::PointXYZ> seg;
      seg.setInputCloud (cloud);
      seg.setIndices (indices);
      //手工设置前景约束点
      pcl::PointCloud<pcl::PointXYZ>::Ptr foreground_points(new pcl::PointCloud<pcl::PointXYZ> ());
      pcl::PointXYZ point;
      point.x = 68.97;
      point.y = -18.55;
      point.z = 0.57;
      foreground_points->points.push_back(point);
      seg.setForegroundPoints (foreground_points);


      seg.setSigma (0.25);             // smooth cost的sigma
      seg.setRadius (3.0433856);       // 以对象为中心,在该半径之外没有属于前景的点
      seg.setNumberOfNeighbours (14); // 构建图的邻点数
      seg.setSourceWeight (0.8);      // 点云各个点与source之间边的权重(foreground penalty )
      std::vector <pcl::PointIndices> clusters;
      seg.extract (clusters);
      // 分割的最大流量值
      std::cout << "Maximum flow is " << seg.getMaxFlow () << std::endl;

      pcl::PointCloud <pcl::PointXYZRGB>::Ptr colored_cloud = seg.getColoredCloud ();
      pcl::visualization::CloudViewer viewer ("Cluster viewer");
      viewer.showCloud(colored_cloud);
      while (!viewer.wasStopped ())
      {
      }

      return (0);
}

CMakeLists.txt

cpp 复制代码
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(min_cut_segmentation)

find_package(PCL 1.5 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (min_cut_segmentation min_cut_segmentation.cpp)
target_link_libraries (min_cut_segmentation ${PCL_LIBRARIES})

数据样例

编译并运行

cpp 复制代码
./min_cut_segmentation
相关推荐
黄晓魚2 个月前
MechMind结构光相机 采图SDK python调用
开发语言·图像处理·python·计算机视觉·pcl·点云处理
stay hungry foolish2 个月前
PCL + Qt + Ribbon 风格(窗口自由组合) demo展示
c++·后端·spring cloud·ribbon·vtk·pcl
coco_1998_23 个月前
Ubuntu22.04 搭建 PCL 环境(VTK源码安装),PCL测试代码
linux·vtk·点云·pcl
RobotsRuning3 个月前
Ubuntu 18.04 安装 PCL 1.14.1
c++·ubuntu·pcl
J ..3 个月前
RandLA-Net 训练自定义数据集
pcl·训练·randla-net
LiDAR点云4 个月前
PCL平面多边形可视化
点云·pcl·多边形可视化
master cat5 个月前
KDTree索引(K近邻搜索,半径R内近邻搜索)——PCL
点云·pcl·kdtree
jjm20027 个月前
Windows10安装PCL1.14.0及点云配准
c++·visualstudio·pcl·点云配准
YANQ6628 个月前
11.2 PCL从ROS获取激光雷达的点云数据及处理
ros·点云·pcl·激光雷达