002: pcl point cloud projection

ModelCoefficients.h and corresponding filter 1. First, the plane containing the projection project_inlier.h

#include <iostream>

#include <pcl/io/pcd_io.h>

#include <pcl/point_types.h>

#include <pcl/ModelCoefficients.h>

#include <pcl/filters/project_inliers.h>

2. Create a point cloud object pointer and initialize the output to the screen

/2.初始化该对象

  cloud->width  = 5;//对于未组织的点云的相当于points个数

  cloud->height = 1; //对未组织的点云指定为1

  cloud->points.resize (cloud->width * cloud->height); //修剪或追加值初始化的元素

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

  {

    cloud->points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);

    cloud->points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);

    cloud->points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);

  }

  // 3.cerr 输出对象放置刷屏

  std::cerr << "Cloud before projection: " << 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;

//投影前点
`Cloud before projection:
    1.28125 577.094 197.938
    828.125 599.031 491.375
    358.688 917.438 842.563
    764.5 178.281 879.531
    727.531 525.844 311.281

3. Set ModelCoefficients value. In this case, we use a model plane, wherein ax + by + cz + d = 0, where a = b = d = 0, c = 1, or in other words, XY plane

  // 4.创建一个系数为X=Y=0,Z=1的平面

  pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());

  coefficients->values.resize (4);

  coefficients->values[0] = coefficients->values[1] = 0;

  coefficients->values[2] = 1.0;

  coefficients->values[3] = 0;

4. By this filtering all points projected onto a plane created, and outputs the result
** Note that before creating a filtered object is not standardized, the program start time should be placed when in use **

  //5.创建滤波后对象,并通过滤波投影,并显示结果

  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_projected(new 
pcl::PointCloud<pcl::PointXYZ>);

  // 创建滤波器对象

  pcl::ProjectInliers<pcl::PointXYZ> proj;

  proj.setModelType (pcl::SACMODEL_PLANE);

  proj.setInputCloud (cloud);

  proj.setModelCoefficients (coefficients);

  proj.filter (*cloud_projected);

  std::cerr << "Cloud after projection: " << std::endl;

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

    std::cerr << "    " << cloud_projected->points[i].x << " " 

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

                        << cloud_projected->points[i].z << std::endl;
  return (0);
//投影后点
Cloud before projection:
    1.28125 577.094 197.938
    828.125 599.031 491.375
    358.688 917.438 842.563
    764.5 178.281 879.531
    727.531 525.844 311.281
Cloud after projection:
    1.28125 577.094 0
    828.125 599.031 0
    358.688 917.438 0
    764.5 178.281 0
    727.531 525.844 0

6. Reference Site
pcl official website routines
have api and examples of all-in_one in, but specific theory or explanation refer to the official Internet!
... \ PCL-1.8.1-AllInOne- msvc2017-win64 (1) \ share \ doc \ pcl-1.8 \ tutorials \ sources in the example to the whole proficient than the entry-pcl

Guess you like

Origin www.cnblogs.com/codeAndlearn/p/11613601.html