• pcl-常用小知识


    pcl-常用小知识

    计算时间

    #include <pcl/console/time.h>
    
    pcl::console::TicToc timer;
    timer.tic();
    //do something
    std::cout << time.toc() << std::endl;
    
    • 计算时间的单位为毫米。

    查找点云的极值

    #include <pcl/point_types.h>
    #include <pcl/common/common.h>
    #include <pcl/io/pcd_io.h>
    
    pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>);
    pcl::io::loadPCDFile<pcl::PointXYZI>("file_dir", *cloud);
    
    pcl::PointXYZI min_pt, max_pt;
    pcl::getMinMax3D(*cloud, min_pt, max_pt);
    

    拷贝点云

    • 拷贝全部点云
    #include <pcl/io/pcd_io.h>
    #include <pcl/common/impl/io.hpp>
    #include <pcl/point_types.h>
    #include <pcl/point_cloud.h>
     
    pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>);
    pcl::io::loadPCDFile<pcl::PointXYZI>("file_dir", *cloud);
    
    pcl::PointCloud<pcl::PointXYZI>::Ptr cloudOut(new pcl::PointCloud<pcl::PointXYZI>);
    pcl::copyPointCloud(*cloud, *cloudOut);
    
    • 拷贝部分点云
    #include <pcl/io/pcd_io.h>
    #include <pcl/point_types.h>
    #include <pcl/point_cloud.h>
     
    pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>);
    pcl::PointCloud<pcl::PointXYZI>::Ptr cloudOut(new pcl::PointCloud<pcl::PointXYZI>);
    pcl::io::loadPCDFile<pcl::PointXYZI>("file_dir", *cloud);
    
    std::vector<int > indexs = { 1, 2, 5 };
    pcl::copyPointCloud(*cloud, indexs, *cloudOut);
    

    去除nan点

    #include <pcl/point_cloud.h>
    #include <pcl/point_types.h>
    #include <pcl/filters/filter.h>
    #include <pcl/io/pcd_io.h>
    
    pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>);
    pcl::PointCloud<pcl::PointXYZI>::Ptr out_cloud(new pcl::PointCloud<pcl::PointXYZI>);
    pcl::io::loadPCDFile<pcl::PointXYZI>("file_dir", *cloud);
    
    std::vector<int> indices;
    pcl::removeNaNFromPointCloud(*cloud, *out_cloud, indices);
    

    点云坐标变换

    #include <pcl/io/pcd_io.h>
    #include <pcl/point_types.h>
    #include <pcl/point_cloud.h>
    #include <pcl/common/transforms.h>
    
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PointCloud<pcl::PointXYZ>::Ptr trans_cloud (new pcl::PointCloud<pcl::PointXYZ>);
    Eigen::Matrix4f transform_matrix = Eigen::Matrix4f::Identity();
    
    pcl::transformPointCloud(*cloud,*trans_cloud,transform_matrix);
    

    读取和写入pcd文件

    Reading Point Cloud data from PCD files

    #include <iostream>
    
    #include <pcl/io/pcd_io.h>
    #include <pcl/point_types.h>
    
    int main (int argc, char** argv)
    {
      pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
    
      if (pcl::io::loadPCDFile<pcl::PointXYZ> ("test_pcd.pcd", *cloud) == -1) //* load the file
      {
        PCL_ERROR ("Couldn't read file test_pcd.pcd 
    ");
        return (-1);
      }
    
      return (0);
    }
    

    Writing Point Cloud data to PCD files

    #include <iostream>
    #include <pcl/io/pcd_io.h>
    #include <pcl/point_types.h>
    
    int main (int argc, char** argv)
    {
      pcl::PointCloud<pcl::PointXYZ> cloud;
    
      // Fill in the cloud data
      cloud.width    = 5;
      cloud.height   = 1;
      cloud.is_dense = false;
      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);
      }
    
      pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
      std::cerr << "Saved " << cloud.points.size () << " data points to test_pcd.pcd." << 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;
    
      return (0);
    }
    

    Concatenate the points of two Point Clouds

    • If we are trying to concatenate points then the code below:
        cloud_c  = cloud_a;
        cloud_c += cloud_b;
    

    creates cloud_c by concatenating the points of cloud_a and cloud_b together.

    • Otherwise if we are attempting to concatenate fields then the code below:
        pcl::concatenateFields (cloud_a, n_cloud_b, p_n_cloud_c);
    

    creates p_n_cloud_c by concatenating the fields of cloud_a and cloud_b together.

  • 相关阅读:
    图片合成
    ASP.net常用对象之一(Request对象)
    vs2010新增功能
    ASP.NET MVC 入门5、View与ViewData【转】
    ASP.NET MVC 入门3、Routing【转】
    ASP.NET MVC 入门2、项目的目录结构与核心的DLL[转]
    ASP.NET MVC 入门4、Controller与Action【转】
    jquery相关文摘
    application技术整理
    vb datagrid中的欄目順序要與recordset的順序一致
  • 原文地址:https://www.cnblogs.com/ChrisCoder/p/10083783.html
Copyright © 2020-2023  润新知