project_inliers滤波

来源:互联网 发布:cfve软件 编辑:程序博客网 时间:2024/05/20 23:34
#include <iostream>
#include <pcl io=""pcd_io.h="">
#include <pcl point_types.h="">
#include <pcl modelcoefficients.h="">
#include <pcl filters=""project_inliers.h="">
 
#include <pcl io=""io.h=""
#include <pcl cloud_viewer.h=""visualization=""
#include <boost thread=""thread.hpp=""
 
intuser_data;
void
viewerOneOff(pcl::visualization::PCLVisualizer& viewer)
{
    viewer.setBackgroundColor(1.0,0.5,1.0);
    pcl::PointXYZ o;
    o.x = 1.0;
    o.y = 0;
    o.z = 0;
    viewer.addSphere(o,0.25,"sphere",0);
    std::cout << "i only run once" << std::endl;
 
}
 
void
viewerPsycho(pcl::visualization::PCLVisualizer& viewer)
{
    staticunsigned count = 0;
    std::stringstream ss;
    ss << "Once per viewer loop: " << count++;
    viewer.removeShape("text",0);
    viewer.addText(ss.str(),200,300,"text",0);
    //FIXME: possible race condition here: 
    user_data++;
}
 
int
 main (intargc, char** argv)
{
     pcl::PointCloud<pcl::pointxyzi>::Ptr cloud(newpcl::PointCloud<pcl::pointxyzi>);
     pcl::PointCloud<pcl::pointxyzi>::Ptr cloud_projected(newpcl::PointCloud<pcl::pointxyzi>);
 
     // 填入点云数据 
     pcl::io::loadPCDFile("table_scene_lms400.pcd", *cloud);
 
     std::cerr << "PointCloud before projection: " << cloud->width * cloud->height
         <<" data points (" << pcl::getFieldsList(*cloud_projected) << ").";
 
  // 创建一个系数为X=Y=0,Z=1的平面
  pcl::ModelCoefficients::Ptr coefficients (newpcl::ModelCoefficients ());
  coefficients->values.resize (4);
  coefficients->values[0] = coefficients->values[1] = 0;
  coefficients->values[2] = 1.0;
  coefficients->values[3] = 0;
  // 创建滤波器对象
  pcl::ProjectInliers<pcl::pointxyzi> proj;
  proj.setModelType (pcl::SACMODEL_PLANE);
  proj.setInputCloud (cloud);
  proj.setModelCoefficients (coefficients);
  proj.filter (*cloud_projected);
 
  std::cerr <<std::endl<< after=""cloud_projected-=""pointcloud=""projection:="">width * cloud_projected->height
      <<" data points (" << pcl::getFieldsList(*cloud_projected) << ").";
 
  pcl::visualization::PCLVisualizer viewer("PCLVisualizer");
  viewer.initCameraParameters();
 
  intv1(0);
  viewer.createViewPort(0.0,0.0,0.5,1.0, v1);
  viewer.setBackgroundColor(1.0,0.5,1.0, v1);
  viewer.addText("Cloud before projection",10,10,"v1 test", v1);
  pcl::visualization::PointCloudColorHandlerGenericField<pcl::pointxyzi> cloud_color(cloud, "intensity");
  viewer.addPointCloud<pcl::pointxyzi>(cloud, cloud_color, "cloud", v1);
 
  intv2(0);
  viewer.createViewPort(0.5,0.0,1.0,1.0, v2);
  viewer.setBackgroundColor(1.0,0.5,1.0, v2);
  viewer.addText("Cloud after projection",10,10,"v2 test", v2);
  pcl::visualization::PointCloudColorHandlerGenericField<pcl::pointxyzi> cloud_afterfilter_color(cloud_projected, "intensity");
  viewer.addPointCloud<pcl::pointxyzi>(cloud_projected, cloud_afterfilter_color, "cloud_projected", v2);
 
  viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,1,"cloud");
  viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,1,"cloud_projected");
 
 
  while(!viewer.wasStopped())
  {
      //在此处可以添加其他处理 
      user_data++;
      viewer.spinOnce(100);
      boost::this_thread::sleep(boost::posix_time::microseconds(100000));
  }
 
  return(0);
}
</pcl::pointxyzi></pcl::pointxyzi></pcl::pointxyzi></pcl::pointxyzi></std::endl<<></pcl::pointxyzi></pcl::pointxyzi></pcl::pointxyzi></pcl::pointxyzi></pcl::pointxyzi></boost></pcl></pcl></pcl></pcl></pcl></pcl></iostream>

运行,右边投影后是一个平面:

 

 

 

0 0
原创粉丝点击