使用liblas实现点云las格式转pcd格式

本文介绍如何在MacBook上使用Xcode通过liblas及pcl点云库将las格式点云数据转换为pcd格式。文章提供了具体步骤及示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用pcl点云库进行程序编写的时候,其内定的点云数据格式类型为pcd,但是当前通用的点云格式大多是las,所以将las格式转成pcd格式使用对于pcl编程来说有一定的意义。根据自己查的网络资料,下面介绍一下在我的macbook上使用xcode调用liblas以及pcl点云库实现las转成pcd格式的方法。

下面程序的前提是首先配置好liblas(liblas可以用hombrew直接装,装完之后在xcode配置的时候加上静态库,再设置好include和lib的路径就可以调用了),我在macbook上配置liblas用的是homebrew直接安装,方便快捷,完事儿之后直接在xcode工程中关联,之后调用下面代码就可以运行了,希望可以给有需要的朋友提供一些帮助。

#include <iostream>
#include <fstream>
#include <string>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

#include <liblas/liblas.hpp>


using namespace std;


int main()
{
    //确定las文件输入路径以及pcd文件输出路径
    const char* lasfile = “abc.las”;
    const char* pcdfile = “123.pcd”;
    
    std::ifstream ifs;
    ifs.open(lasfile, std::ios::in | std::ios::binary);
    
    liblas::ReaderFactory f ; 
    liblas::Reader reader = f.CreateWithStream(ifs);    
    liblas::Header const& header = reader.GetHeader();
  
    pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloudPtr(new pcl::PointCloud<pcl::PointXYZ>);
    int count = header.GetPointRecordsCount();
    pointCloudPtr->resize(count);
    pointCloudPtr->width = 1;
    pointCloudPtr->height = count;
    pointCloudPtr->is_dense = false;
    
    int i = 0;
    while (reader.ReadNextPoint())
    {
        liblas::Point const& p = reader.GetPoint();
        pointCloudPtr->points[i].x = p.GetX();
        pointCloudPtr->points[i].y = p.GetY();
        pointCloudPtr->points[i].z = p.GetZ();
        ++i;
    }
    pcl::io::savePCDFileASCII(pcdfile,*pointCloudPtr);
    return (0);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值