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.

  • 相关阅读:
    react-redux源码解析
    redux的源码解析
    react + dva + ant架构后台管理系统(一)
    fetch 代替 XMLHttpRequest (json-server 模拟后台接口)
    Es6 Generator函数
    java 的数据类型
    vue为app做h5页面,如何做到同域名对应不同版本的h5代码
    vue-devtools 的安装和使用
    jq源码解析之绑在$,jQuery上面的方法
    jquery的extend方法(源码解析)
  • 原文地址:https://www.cnblogs.com/ChrisCoder/p/9986346.html
Copyright © 2011-2022 走看看