PCL小工具三:pcd点云文件转为txt格式

在一些奇怪的地方,特别是不用c++的地方。点云文件需要转为txt格式的文件,方便调用。
本文写了一个小工具用于把pcd文件转为txt格式

src/pcd2txt.cpp

#include 
#include   
#include   
#include 

using namespace std;

void pclDownsize(pcl::PointCloud<pcl::PointXYZ>::Ptr in, pcl::PointCloud<pcl::PointXYZ>::Ptr out)
{
    pcl::VoxelGrid<pcl::PointXYZ> down_filter;
    float leaf = 0.1;
    down_filter.setLeafSize(leaf, leaf, leaf);
    down_filter.setInputCloud(in);
    down_filter.filter(*out);
}


int main(int argc, char *argv[])
{
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
    // pcl::PointCloud::Ptr cloud_out(new pcl::PointCloud);
    // Fill in the cloud data  
    if (pcl::io::loadPCDFile<pcl::PointXYZ>("/home/jy/Desktop/2011_09_30/2011_09_30_drive_0027_sync/velodyne_points/out_fliter_010.pcd", *cloud) == -1)
    {
        PCL_ERROR("Couldn't read file chuli.pcd\n");
        return (-1);
    }
    // pclDownsize(cloud,cloud_out);

    cout << "points cloud is successfully loaded! " << endl;
    //for (size_t i = 0; i < cloud->points.size(); i++)
    //  std::cout << " " << cloud->points[i].x << " " << cloud->points[i].y
    //  <<" "<< cloud->points[i].z << std::endl;
    int Num = cloud->points.size();
    double *X = new double[Num] {0};
    double *Y = new double[Num] {0};
    double *Z = new double[Num] {0};
    cout << "size is : " << cloud->points.size() << endl;
    for (size_t i = 0; i <  cloud->points.size(); ++i)
    {
        X[i] = cloud->points[i].x;
        Y[i] = cloud->points[i].y;
        Z[i] = cloud->points[i].z ; 
        cout << "first  " << i << " of " << Num << endl;
    }

    
    ofstream zos("07_flitered_010.txt");
    for (int i = 0; i< cloud->points.size(); i++)
    {
        zos << X[i] << " " << Y[i] << " " << Z[i] << endl;
        cout << "second  " << i << " of " << Num << endl;
    }
    cout << "trans has done!!!" << endl;
    // cin.get();
    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

set(CMAKE_BUILD_TYPE "Release")
# 添加c++ 11标准支持
set(CMAKE_CXX_FLAGS "-std=c++11 -O2")

find_package(PCL REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})

add_executable (pcd2txt src/pcd2txt.cpp) #注意这里不能替换
target_link_libraries(pcd2txt ${PCL_LIBRARIES})


你可能感兴趣的:(PCL库的简单使用,c++,人工智能)