zoukankan      html  css  js  c++  java
  • 【PCL学习三】如何写一个pcd文件

    环境:Ubuntu16.04

    一、文件夹内创建pcd_write.cpp 和 CMakeLists.txt 文件

    pcd_write.cpp

    #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 (auto& point: cloud)
      {
        point.x = 1024 * rand () / (RAND_MAX + 1.0f);
        point.y = 1024 * rand () / (RAND_MAX + 1.0f);
        point.z = 1024 * rand () / (RAND_MAX + 1.0f);
      }
    
      pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
      std::cerr << "Saved " << cloud.size () << " data points to test_pcd.pcd." << std::endl;
    
      for (const auto& point: cloud)
        std::cerr << "    " << point.x << " " << point.y << " " << point.z << std::endl;
    
      return (0);
    }

    CMakeLists.txt

    cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
    
    project(pcd_write)
    
    find_package(PCL 1.2 REQUIRED)
    
    include_directories(${PCL_INCLUDE_DIRS})
    link_directories(${PCL_LIBRARY_DIRS})
    add_definitions(${PCL_DEFINITIONS})
    
    add_executable (pcd_write pcd_write.cpp)
    target_link_libraries (pcd_write ${PCL_LIBRARIES})

    二、编译

    创建build文件夹

    mkdir build
    cd build
    cmake ..
    make

    编译后生成 pcd_write可执行程序

    运行pcd_write程序

    ./pcd_write

    生成  test_pcd.pcd。

    cat查看pcd文件内容

    cat test_pcd.pcd

    如果想要看一下这个pcd的点云,使用pcl_viewer

    pcl_viewer test_pcd.pcd

    可以看到5个点

    测试完成

    Talk is cheap, show me the code
  • 相关阅读:
    Linux 设置主机名和 IP 地址的映射关系
    Zookeeper 数据查看工具 ZooInspector 的使用
    Zookeeper 集群
    Zookeeper 监控指定节点数据变化
    Zookeeper 常用命令
    Spring整合ActiveMQ持久化到Mysql数据库
    Activemq5.15.5持久化到mysql8.0.20
    ActiveMQ支持的协议
    SIGINT SIGTERM SIGKILL区别
    lograte -日志轮询log
  • 原文地址:https://www.cnblogs.com/birdBull/p/14473338.html
Copyright © 2011-2022 走看看