PCL-Cpp (70%)

1. PassThrough

์ฝ”๋“œ๋Š” [์ด๊ณณ]์—์„œ ๋‹ค์šด๋กœ๋“œ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์ƒ˜ํ”ŒํŒŒ์ผ์€ [tabletop.pcd]์„ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/passthrough.h>

//Filtering a PointCloud using a PassThrough filter
//http://pointclouds.org/documentation/tutorials/passthrough.php#passthrough

int
 main (int argc, char** argv)
{
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZRGB>);

  // *.PCD ํŒŒ์ผ ์ฝ๊ธฐ (https://raw.githubusercontent.com/adioshun/gitBook_Tutorial_PCL/master/Beginner/sample/tabletop.pcd)
  pcl::io::loadPCDFile<pcl::PointXYZRGB> ("tabletop.pcd", *cloud);

  // ํฌ์ธํŠธ์ˆ˜ ์ถœ๋ ฅ
  std::cout << "Loaded :" << cloud->width * cloud->height  << std::endl;

  // ์˜ค๋ธŒ์ ํŠธ ์ƒ์„ฑ 
  pcl::PassThrough<pcl::PointXYZRGB> pass;
  pass.setInputCloud (cloud);                //์ž…๋ ฅ 
  pass.setFilterFieldName ("z");             //์ ์šฉํ•  ์ขŒํ‘œ ์ถ• (eg. Z์ถ•)
  pass.setFilterLimits (0.70, 1.5);          //์ ์šฉํ•  ๊ฐ’ (์ตœ์†Œ, ์ตœ๋Œ€ ๊ฐ’)
  //pass.setFilterLimitsNegative (true);     //์ ์šฉํ•  ๊ฐ’ ์™ธ 
  pass.filter (*cloud_filtered);             //ํ•„ํ„ฐ ์ ์šฉ 

  // ํฌ์ธํŠธ์ˆ˜ ์ถœ๋ ฅ
  std::cout << "Filtered :" << cloud_filtered->width * cloud_filtered->height  << std::endl;  

  // ์ €์žฅ 
  pcl::io::savePCDFile<pcl::PointXYZRGB>("tabletop_passthrough.pcd", *cloud_filtered); //Default binary mode save

  return (0);
}

์‹คํ–‰ & ๊ฒฐ๊ณผ

$ Loaded :202627
$ Filtered :72823

์‹œ๊ฐํ™” & ๊ฒฐ๊ณผ

$ pcl_viewer tabletop.pcd 
$ pcl_viewer tabletop_passthrough.pcd

์›๋ณธ

๊ฒฐ๊ณผ

๊ฒฐ๊ณผ(Negative)

2. Conditional Outlier removal

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/conditional_removal.h>

//Removing outliers using a Conditional or RadiusOutlier removal
//http://pointclouds.org/documentation/tutorials/remove_outliers.php#remove-outliers

int
 main (int argc, char** argv)
{

  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZRGB>);

  // *.PCD ํŒŒ์ผ ์ฝ๊ธฐ (https://raw.githubusercontent.com/adioshun/gitBook_Tutorial_PCL/master/Beginner/sample/tabletop.pcd)
  pcl::io::loadPCDFile<pcl::PointXYZRGB> ("tabletop.pcd", *cloud);

  // ํฌ์ธํŠธ์ˆ˜ ์ถœ๋ ฅ
  std::cout << "Loaded " << cloud->width * cloud->height  << std::endl;

  // ์กฐ๊ฑด ์ •์˜ 
  pcl::ConditionAnd<pcl::PointXYZRGB>::Ptr range_cond (new pcl::ConditionAnd<pcl::PointXYZRGB> ());
  range_cond->addComparison (pcl::FieldComparison<pcl::PointXYZRGB>::ConstPtr (new //์กฐ๊ฑด 1 
     pcl::FieldComparison<pcl::PointXYZRGB> ("z", pcl::ComparisonOps::GT, 0.0)));  //eg. z์ถ•์œผ๋กœ 0.00๋ณด๋‹ค ํฐ๊ฐ’(GT:Greater Than)
  range_cond->addComparison (pcl::FieldComparison<pcl::PointXYZRGB>::ConstPtr (new //์กฐ๊ฑด 2 
     pcl::FieldComparison<pcl::PointXYZRGB> ("z", pcl::ComparisonOps::LT, 0.8)));  //eg. z์ถ•์œผ๋กœ 0.08๋ณด๋‹ค ์ž‘์€๊ฐ’(LT:Less Than)

  //์˜คํ”„์ ํŠธ ์ƒ์„ฑ 
  pcl::ConditionalRemoval<pcl::PointXYZRGB> condrem;
  condrem.setInputCloud (cloud);        //์ž…๋ ฅ 
  condrem.setCondition (range_cond);    //์กฐ๊ฑด ์„ค์ •  
  condrem.setKeepOrganized(true);       //
  condrem.filter (*cloud_filtered);     //ํ•„ํ„ฐ ์ ์šฉ 

  // ํฌ์ธํŠธ์ˆ˜ ์ถœ๋ ฅ  
  std::cout << "Filtered " << cloud_filtered->width * cloud_filtered->height  << std::endl;

  // ์ €์žฅ 
  pcl::io::savePCDFile<pcl::PointXYZRGB>("tabletop_conditional.pcd", *cloud_filtered); //Default binary mode save
  return (0);
}

์›๋ณธ

๊ฒฐ๊ณผ

Last updated