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

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

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

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

src/pcd2txt.cpp

#include 
#include   
#include   
#include 

using namespace std;

void pclDownsize(pcl::PointCloud::Ptr in, pcl::PointCloud::Ptr out)
{
    pcl::VoxelGrid 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::Ptr cloud(new pcl::PointCloud);
    // pcl::PointCloud::Ptr cloud_out(new pcl::PointCloud);
    // Fill in the cloud data  
    if (pcl::io::loadPCDFile("/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.pcdn");
        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})


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4751389.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-08
下一篇 2022-11-08

发表评论

登录后才能评论

评论列表(0条)

保存