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

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

src/pcd2txt.cpp

#include <iostream>
#include <pcl/io/pcd_io.h>  
#include <pcl/point_types.h>  
#include <pcl/filters/voxel_grid.h>

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<pcl::PointXYZ>::Ptr cloud_out(new pcl::PointCloud<pcl::PointXYZ>);
    // 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})


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山楂没我渣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值