zoukankan      html  css  js  c++  java
  • pcl之投影点云到参数模型上

    pcl之projecting points using a parametric model

    In this tutorial we will learn how to project points onto a parametric model (e.g., plane, sphere, etc). The parametric model is given through a set of coefficients – in the case of a plane, through its equation: ax + by + cz + d = 0.

    #include <iostream>
    #include <pcl/io/pcd_io.h>
    #include <pcl/point_types.h>
    #include <pcl/ModelCoefficients.h>
    #include <pcl/filters/project_inliers.h>
    
    int main (int argc, char** argv)
    {
      pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
      pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_projected (new pcl::PointCloud<pcl::PointXYZ>);
    
      // Fill in the cloud data
      cloud->width  = 5;
      cloud->height = 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);
      }
    
      // Create a set of planar coefficients with 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;
    
      // Create the filtering object
      pcl::ProjectInliers<pcl::PointXYZ> proj;
      proj.setModelType (pcl::SACMODEL_PLANE);
      proj.setInputCloud (cloud);
      proj.setModelCoefficients (coefficients);
      proj.filter (*cloud_projected);
    
      return (0);
    }
    

    We fill in the ModelCoefficients values. In this case, we use a plane model, with ax+by+cz+d=0, where a=b=d=0, and c=1, or said differently, the X-Y plane.

    Cloud before projection:
        0.352222 -0.151883 -0.106395
        -0.397406 -0.473106 0.292602
        -0.731898 0.667105 0.441304
        -0.734766 0.854581 -0.0361733
        -0.4607 -0.277468 -0.916762
    Cloud after projection:
        0.352222 -0.151883 0
        -0.397406 -0.473106 0
        -0.731898 0.667105 0
        -0.734766 0.854581 0
        -0.4607 -0.277468 0
    

    Note that the coordinate axes are represented as red (x), green (y), and blue (z). The five points are represented with red as the points before projection and green as the points after projection. Note that their z now lies on the X-Y plane.

  • 相关阅读:
    [贪心]P1049 装箱问题
    js中字符串转换为日期和比较大小
    weblogic配置数据源出错
    myeclipse安装svn插件的多种方式
    使用令牌实现防重复提交
    struts1.3异常处理机制
    spring log4j.properties
    spring jdbc.property的配置与使用
    js循环array,json,map
    java web的一些特殊用法(一)
  • 原文地址:https://www.cnblogs.com/ChrisCoder/p/9986346.html
Copyright © 2011-2022 走看看