-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplane_segmentation.cpp
45 lines (32 loc) · 1.23 KB
/
plane_segmentation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "plane_segmentation.h"
using namespace pebcl;
planeSegmentor::planeSegmentor(pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud)
{
pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients);
pcl::PointIndices::Ptr inliers (new pcl::PointIndices);
// Create the segmentation object
pcl::SACSegmentation<pcl::PointXYZRGB> seg;
// Optional
seg.setOptimizeCoefficients (true);
// Mandatory
seg.setModelType (pcl::SACMODEL_PLANE);
seg.setMethodType (pcl::SAC_RANSAC);
seg.setDistanceThreshold (0.02);
seg.setMaxIterations (100);
seg.setInputCloud (cloud);
seg.segment (*inliers, *coefficients);
if (inliers->indices.size () == 0)
{
PCL_THROW_EXCEPTION (pcl::PCLException, "Could not estimate a planar model for the given dataset.");
}
this->MC = coefficients;
this->PI = inliers;
std::cerr << "Model coefficients: " << coefficients->values[0] << " "
<< coefficients->values[1] << " "
<< coefficients->values[2] << " "
<< coefficients->values[3] << std::endl;
std::cerr << "Number of inliers : " << inliers->indices.size() << std::endl;
}
planeSegmentor::~planeSegmentor()
{
}