点云las格式转pcd格式(c++实现)

0、介绍

liblas库是一个开源库,提供了一系列对Lidar数据.las格式的读写等操作函数。

1、安装

git clone https://github.com/libLAS/libLAS.git
cd libLAS/
mkdir build && cd build
cmake ..
make
sudo make install

2、查看点云信息 

# sudo apt install liblas-bin
lasinfo test.las

3、las格式转pcd格式

main.cc:

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

int main() {
    const char* lasfile = "/tmp/test.las";
    const char* pcdfile = "/tmp/test.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();

    std::cout << "Compressed: " << (header.Compressed() == true? "True" : "False") << std::endl;
    std::cout << "Signature: " << header.GetFileSignature() << std::endl;

    pcl::PointCloud<pcl::PointXYZI>::Ptr pointCloudPtr(new pcl::PointCloud<pcl::PointXYZI>);
    int count = header.GetPointRecordsCount();
    pointCloudPtr->width = 1;
    pointCloudPtr->height = count;
    pointCloudPtr->is_dense = false;
    pointCloudPtr->resize(pointCloudPtr->width * pointCloudPtr->height);

    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();
        pointCloudPtr->points[i].intensity = p.GetIntensity();

        ++i;
    }
    pcl::io::savePCDFileASCII(pcdfile, *pointCloudPtr);

    return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(test)

set(CMAKE_CXX_STANDARD 11)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

find_package(PCL 1.2 REQUIRED)
find_package(libLAS REQUIRED)

message("include: "${libLAS_INCLUDE_DIRS})
message("libraries: "${libLAS_LIBRARIES})

include_directories(${PCL_INCLUDE_DIRS} ${libLAS_INCLUDE_DIRS})
add_executable(test main.cc)
target_link_libraries(test
        ${libLAS_LIBRARIES}
        ${PCL_LIBRARIES})

参考:

https://github.com/libLAS/libLAS

  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
点云数据主要有多种格式,其las格式pcd格式是常见的两种格式。其las格式是由美国ASPRS(American Society for Photogrammetry and Remote Sensing)制定的一种点云数据标准格式,而PCD格式则是由ROS(Robot Operating System)定义的点云数据格式,适用于机器人与物体感知领域。 点云las格式pcd格式数据结构、数据类型以及文件格式上存在差异,因此需要使用相应的工具完成格式换。常见的工具包括pcl库、CloudCompare、Pointfuse等,下面主要讲述使用pcl库完成点云las格式pcd格式换。 pcl库是一套可重用的库,包含了多种点云处理和分析方法。使用pcl库进行点云数据换需要安装pcl库并建立好相应的编译环境。以下是具体步骤: 1. 安装pcl库 安装pcl库需要在官网上下载对应的代码,并按照说明进行编译和安装。这里不再赘述。 2. 使用pcl库点云格式 使用pcl库进行点云数据换,需要调用pcl::io::LasIO类的readLasFile和writePCDFile两个函数进行las格式pcd格式换。具体代码如下: #include <pcl/io/pcd_io.h> #include <pcl/io/io.h> #include <pcl/io/las_io.h> #include <pcl/point_types.h> int main() { // 加载las格式点云数据文件 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); pcl::io::loadLASFile("/path/to/your/las/file.las", *cloud); // 将las格式点云数据文件以pcd格式保存 pcl::io::savePCDFileASCII("/path/to/your/pcd/file.pcd", *cloud); return 0; } 以上代码实现了使用pcl库将las格式点云数据文件换成pcd格式,并保存到指定的文件路径。需要注意的是,代码的路径需要根据实际的文件路径进行修改。 总之,使用pcl库进行点云数据格式换是一种简单、高效的方法。除了pcl库,还有其他的工具可供选择,具体选择哪种工具,可以根据实际情况和需求来确定。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值