1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PCLによる平面の検出

Posted at

点群から平面を検出する.

#基本
処理の流れとしては

  1. 検出器を宣言し各パラメータを設定
  2. 入力点群を検出器にセット
  3. 平面検出を実行
    となる.
#include <pcl/segmentation/sac_segmentation.h>

//入力点群
pcl::PointCloud<pcl::PointXYZ> input_pointcloud;
//点群をセットする処理.push_backとかでやってください

//平面方程式と平面と検出された点のインデックス
pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients);
pcl::PointIndices::Ptr inliers(new pcl::PointIndices);

//RANSACによる検出.
pcl::SACSegmentation<pcl::PointXYZ> seg;
seg.setOptimizeCoefficients(true); //外れ値の存在を前提とし最適化を行う
seg.setModelType(pcl::SACMODEL_PLANE); //モードを平面検出に設定
seg.setMethodType(pcl::SAC_RANSAC); //検出方法をRANSACに設定
seg.setDistanceThreshold(0.005); //しきい値を設定
seg.setInputCloud(raw_pointcloud.makeShared()); //入力点群をセット
seg.segment(*inliers, *coefficients); //検出を行う

ここまで実行するとinliersとcoefficientsに検出結果が入る.

#応用
平面の点群を取得したいときは

#include <pcl/filters/extract_indices.h>

pcl::PointCloud<pcl::PointXYZ> plane_pointcloud;
pcl::ExtractIndices<pcl::PointXYZ> extract;
extract.setInputCloud(raw_pointcloud.makeShared());
extract.setIndices(inliers);
extract.setNegative(false);
extract.filter(plane_pointcloud);

逆に平面の点群を除去したいときはsetNegativeにtrueを入れる.

extract.setNegative(true);
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?