從PCD文件讀取數據

首先寫c++文件

#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> ("table_scene_lms400.pcd", *cloud) == -1) //* 讀入PCD格式的文件,如果文件不存在,返回-1
  {
    PCL_ERROR ("Couldn't read file\n");
    return (-1);`在這裏插入代碼片`
  }
  std::cout << "Loaded "
            << cloud->width * cloud->height
            << " data points from pcd with the following fields: "
            << std::endl;
  //for (size_t i = 0; i < cloud->points.size (); ++i) //顯示所有的點
    for (size_t i = 0; i < 5; ++i) // 爲了方便觀察,只顯示前5個點
    std::cout << "    " << cloud->points[i].x
              << " "    << cloud->points[i].y
              << " "    << cloud->points[i].z << std::endl;

  return (0);
}

再寫cmakelist文件

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(pcd_read)

find_package(PCL 1.2 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (pcd_read pcd_read.cpp)
target_link_libraries (pcd_read ${PCL_LIBRARIES})


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章