点云数据格式*.las转*.pcd

本文介绍了两种将LAS点云数据转换为PCD格式的方法。第一种是使用CloudCompare软件,通过拖拽LAS文件并保存为PCD格式。第二种方法涉及编程,利用libLAS库编写C++程序las2pcd.cpp,实现LAS到PCD的转换,并处理可能出现的依赖问题,如libgeotiff和liblas库的安装与链接。
摘要由CSDN通过智能技术生成

方法一: 使用CloudCompare打开*.las并保存为*.pcd格式
安装CloudCompare

sudo snap install cloudcompare

打开cloudcompare图像查看窗口

cloudcompare.ccViewer

打开cloudcompare软件

cloudcompare.CloudCompare

打开CloudCompare软件之后,将*.las文件拖入软件,保存时设置为*.pcd的格式。

方法二: 使用liblas库
liblas库是一个开源库,提供了一系列对Lidar数据.las格式的读写等操作函数
下载liblas软件源码:https://liblas.org/download.html

git clone https://github.com/libLAS/libLAS.git
cd libLAS
mkdir build
cd build
cmake .. 或 cmake -G "Unix Makefiles" ../
make
sudo make install

查看安装是否完成,查看一个*.las文件的相关信息

lasinfo ***.las

程序:
las2pcd.cpp

#include <iostream>
#include <fstream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <liblas/liblas.hpp>
 
int main() {
    const char* lasfile = "../input.las";
    const char* pcdfile = "../output.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(las2pcd)
 
set(CMAKE_CXX_STANDARD 11)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
 
find_package(PCL 1.7 REQUIRED)
find_package(libLAS REQUIRED)
 
message("include: "${libLAS_INCLUDE_DIRS})
message("libraries: "${libLAS_LIBRARIES})
 
include_directories(${PCL_INCLUDE_DIRS} ${libLAS_INCLUDE_DIRS})
add_executable(las2pcd las2pcd.cpp)
target_link_libraries(las2pcd ${libLAS_LIBRARIES} ${PCL_LIBRARIES})

可能会遇到的问题:
1、Unable to find sufficient GeoTIFF
解决方法:安装libgeotiff-1.3.0

wget https://download.osgeo.org/geotiff/libgeotiff/libgeotiff-1.3.0.tar.gz
# 解压后
./configure
make
sudo make install

2、liblas安装时出现:
lasinfo: error while loading shared libraries: liblas.so.3: cannot open shared object file: No such file or directory
以及
lasinfo: error while loading shared libraries: libgeotiff.so.2: cannot open shared object file: No such file or directory

解决方法:
libLAS-1.8.1/build/bin/Release

sudo cp liblas.so.3 /usr/lib/
sudo cp liblas_c.so.3 /usr/lib/

/usr/local/lib

sudo cp libgeotiff.so.2 /usr/lib/

注:/usr/lib/为动态库文件所在目录

3、make时出现未定义的引用错误

las2pcd.cpp:(.text+0x84): undefined reference to `liblas::ReaderFactory::CreateWithStream(std::istream&)'
las2pcd.cpp:(.text+0x93): undefined reference to `liblas::Reader::GetHeader() const'
las2pcd.cpp:(.text+0x9b): undefined reference to `liblas::Header::GetPointRecordsCount() const'
las2pcd.cpp:(.text+0x111): undefined reference to `liblas::Reader::ReadNextPoint()'
...

原因:Linux程序运行找不到动态库.so文件
解决方法:参考链接

在CMakeLists.txt中,写:

find_package(libLAS REQUIRED)

include_directories(${PCL_INCLUDE_DIRS} ${libLAS_INCLUDE_DIRS})
add_executable(las2pcd las2pcd.cpp)
target_link_libraries(las2pcd ${libLAS_LIBRARIES} ${PCL_LIBRARIES})

或直接指定动态库路径

LINK_LIBRARIES("/usr/local/lib/liblas.so.3")LINK_LIBRARIES("/usr/lib/liblas.so.3")
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值