pcl 提取子集(平面)

2021-07-29 22:25:43 字數 3732 閱讀 1500

在點雲裡提取了一些子集(平面)並顯示出來

參考鏈結

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

int main(int argc, char** argv)

// extract the inliers

extract.setinputcloud(cloud_filtered);

extract.setindices(inliers);

extract.setnegative(false);

extract.filter(*cloud_p);

std::cerr

<<

"pointcloud representing the planar component: "

<< cloud_p->width * cloud_p->height <<

" data points."

<< std::endl;

points.push_back(cloud_p);

std::stringstream ss;

ss <<

"table_scene_lms400_plane_"

<< i <<

".pcd";

writer.write<:pointxyz>

>(ss.str(), *cloud_p, false);

// create the filtering object

extract.setnegative(true);

extract.filter(*cloud_f);

cloud_filtered.swap(cloud_f);//更新

另外乙個** 這個**可以輸出子集的引數(平面引數)

#include 

#include

#include

#include

#include

#include

#include

intmain(int argc, char** argv)

// set a few outliers

cloud->points[0].z = 2.0;

cloud->points[3].z = -2.0;

cloud->points[6].z = 4.0;

std::cerr

<< "point cloud data: "

<< cloud->points.size() << " points"

<< std::endl;

for (size_t i = 0; i < cloud->points.size(); ++i)

std::cerr

<< " "

<< cloud->points[i].x << " "

<< cloud->points[i].y << " "

<< cloud->points[i].z << std::endl;

pcl::modelcoefficients::ptr coefficients(new pcl::modelcoefficients);

pcl::pointindices::ptr inliers(new pcl::pointindices);

// create the segmentation object

pcl::sacsegmentationseg;

// optional

seg.setoptimizecoefficients(true);

// mandatory

seg.setmodeltype(pcl::sacmodel_plane);

seg.setmethodtype(pcl::sac_ransac);

seg.setdistancethreshold(0.01);

seg.setinputcloud(cloud);

seg.segment(*inliers, *coefficients);

if (inliers->indices.size() == 0)

std::cerr

<< "model coefficients: "

<< coefficients->values[0] << " "

<< coefficients->values[1] << " "

<< coefficients->values[2] << " "

<< coefficients->values[3] << std::endl;

std::cerr

<< "model inliers: "

<< inliers->indices.size() << std::endl;

for (size_t i = 0; i < inliers->indices.size(); ++i)

std::cerr

<< inliers->indices[i] << " "

<< cloud->points[inliers->indices[i]].x << " "

<< cloud->points[inliers->indices[i]].y << " "

<< cloud->points[inliers->indices[i]].z << std::endl;

return (0);

}

PCL學習3 平面擬合

pcl平面擬合功能位於模組sample consensus中 pcl sample consensus 該模組基於 隨機抽樣一致演算法 random sample consensus 不僅可以用於平面擬合,也可以擬合柱面 球面等,對ransac的簡單解釋 ransac可以從一組包含 局外點 的觀測資...

PCL 使用RANSAC擬合平面

二 示例 三 結果展示 隨機抽樣一致性演算法ransac random sample consensus 是一種迭代的方法來從一系列包含有離異值的資料中計算數學模型引數的方法。ransac演算法本質上由兩步組成,不斷進行迴圈 1 從輸入資料中隨機選出能組成數學模型的最小數目的元素,使用這些元素計算出...

PCL之平面分割模型

展示 include include include include include include include include using namespace std using pointt pcl pointxyz int main 建立分割時所需要的模型係數物件,coefficients...