2018-01-01:Reading Point Cloud data from PCD files

main.cpp

#include
#include
#include

int main(int argc, char** argv)
{
    pcl::PointCloud::Ptr cloud (new pcl::PointCloud);

    if(pcl::io::loadPCDFile("test_pcd.pcd", *cloud)==-1)
    {
        PCL_ERROR("Couldn't read file test_pcd.pcd\n");
        return -1;
    }

    std::cout<<"Loaded "<width*cloud->height<<" data points from test_pcd.pcd with the following fields: "<points.size(); ++i)
    {
        std::cout<<"    "<points[i].x<<" "<points[i].y<<" "<points[i].z<

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
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(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME} ${PCL_LIBRARIES})

execute the program:

./pcd_read test_pcd.pcd

Note: you should keep the pcd file in the same directory

你可能感兴趣的:(2018-01-01:Reading Point Cloud data from PCD files)