在Ubuntu系统下,关于LAS文件转换成pcd文件,出现未定义函数的问题

在阅读《PCL从入门到精通》这本书时,在第三章的las文件转换成pcd文件中。遇到下列问题,(所用系统为Ubuntu18.04):

在执行make时出现如下的错误

pcl@pcl-ROS:~/pclLearn/las2pcd$ make
[ 50%] Linking CXX executable bin/las2pcd
CMakeFiles/las2pcd.dir/las2pcd.cpp.o: In function `main':
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()'
las2pcd.cpp:(.text+0x128): undefined reference to `liblas::Reader::GetPoint() const'
las2pcd.cpp:(.text+0x130): undefined reference to `liblas::Point::GetX() const'
las2pcd.cpp:(.text+0x171): undefined reference to `liblas::Reader::GetPoint() const'
las2pcd.cpp:(.text+0x179): undefined reference to `liblas::Point::GetY() const'
las2pcd.cpp:(.text+0x1bb): undefined reference to `liblas::Reader::GetPoint() const'
las2pcd.cpp:(.text+0x1c3): undefined reference to `liblas::Point::GetZ() const'
las2pcd.cpp:(.text+0x205): undefined reference to `liblas::Reader::GetPoint() const'
las2pcd.cpp:(.text+0x21a): undefined reference to `liblas::Point::GetColor() const'
las2pcd.cpp:(.text+0x23f): undefined reference to `liblas::Reader::GetPoint() const'
las2pcd.cpp:(.text+0x254): undefined reference to `liblas::Point::GetColor() const'
las2pcd.cpp:(.text+0x279): undefined reference to `liblas::Reader::GetPoint() const'
las2pcd.cpp:(.text+0x28e): undefined reference to `liblas::Point::GetColor() const'
las2pcd.cpp:(.text+0x41c): undefined reference to `liblas::Reader::~Reader()'
las2pcd.cpp:(.text+0x49f): undefined reference to `liblas::Reader::~Reader()'
出现libLAS中的相关函数未定义。如果大家用的是随书代码中提供的libLAS的库,应该均会出现此问题。

这是因为随书源码是针对的Windows系统的,提供的库为Windows系统下的静态库和动态库。不适用在Ubuntu系统下。

解决方法:

我们需要自己下载libLAS库的源码进行编译:

1.下载源码:http://download.osgeo.org/liblas/libLAS-1.8.1.tar.bz2,我这里下载的是1.8.1版本的

2. 编译源码:cd libLAS-1.8.1

                        mkdir build

                        cd build

                        cmake ..

                        make

3.将~/libLAS-1.8.1/build/bin/Release目录下的*.so文件复制到las2pcd的源码中。编译运行即可。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
### 回答1: 你可以使用Python中的`laspy`库来将`.las`文件转换为`.pcd`文件。首先,你需要安装`laspy`库,可以使用以下命令: ``` pip install laspy ``` 然后,你可以使用以下代码将`.las`文件转换为`.pcd`文件: ```python import laspy import numpy as np # 读入las文件 inFile = laspy.file.File("input_file.las", mode="r") # 获取点云信息 point_format = inFile.point_format point_records = inFile.points # 将点云信息转换为numpy数组 x = point_records['X'] y = point_records['Y'] z = point_records['Z'] r = point_records['red'] g = point_records['green'] b = point_records['blue'] # 将xyz和rgb组合为一个numpy数组 cloud = np.column_stack((x, y, z, r, g, b)) # 保存为pcd文件 np.savetxt("output_file.pcd", cloud, delimiter=" ", header="VERSION .7\nFIELDS x y z rgb\nSIZE 4 4 4 4\nTYPE F F F U\nCOUNT 1 1 1 1\nDATA ascii") # 关闭las文件 inFile.close() ``` 这将读取`input_file.las`文件,将其转换为包含xyz和rgb信息的numpy数组,并将其保存为`output_file.pcd`文件。 ### 回答2: Python是一种强大的编程语言,可以用于各种数据处理和转换任务。要将.las文件转换为.pcd文件,可以使用Python中的laspy和pypcd库。 首先,我们需要安装这两个库。可以使用以下命令来安装它们: ``` pip install laspy pypcd ``` 安装完成后,我们可以开始编写Python代码来进行转换。 ```python import laspy from pypcd import pypcd # 打开.las文件 in_file = laspy.file.File("input.las", mode="r") # 创建一个新的.pcd文件对象 out_file = pypcd.PointCloud() # 从.las文件中获取点云数据 points = in_file.points # 设置.pcd文件的点云数据 out_file.points = points # 设置点云属性(可选) # 例如,如果.las文件包含RGB颜色信息,可以将其转移到.pcd文件中 if in_file.red is not None and in_file.green is not None and in_file.blue is not None: colors = [(r, g, b) for r, g, b in zip(in_file.red, in_file.green, in_file.blue)] out_file.pc_data["rgb"] = colors # 保存.pcd文件 out_file.save("output.pcd") ``` 在上面的代码中,首先使用laspy库打开输入的.las文件。然后,使用pypcd库创建一个新的.pcd文件对象。接下来,将从.las文件中获取的点云数据设置为.pcd文件对象的点云数据。如果.las文件中包含了RGB颜色信息,还可以将其转移至.pcd文件。最后,使用save()方法将.pcd文件保存到输出文件中。 在以上的代码示例中,我使用的是laspy和pypcd库来进行.las文件到.pcd文件的转换。你也可以使用其他的Python库来完成这个转换任务,具体实现方式可能会有所不同。 ### 回答3: 将.LAS(激光扫描点云)文件转换为.PCD(点云数据)文件是一个常见的任务。Python提供了许多库和工具,可以帮助我们实现这个转换过程。 首先,我们需要安装一些必要的库。使用`pip`命令安装Python的点云库`pyntcloud`和LAS文件处理库`laspy`。 ``` pip install pyntcloud pip install laspy ``` 接下来,我们可以编写一个Python脚本来完成.LAS文件转换为.PCD文件的任务。以下是一个简单的示例: ```python import laspy from pyntcloud import PyntCloud # 读取.LAS文件 las_file = laspy.file.File('input.las', mode='r') # 获取点云数据 points = las_file.points # 创建点云对象 cloud = PyntCloud(pd.DataFrame(points)) # 将点云保存为.PCD文件 cloud.to_file('output.pcd') ``` 在这个脚本中,我们首先使用`laspy`库打开.LAS文件并获取点云数据。然后,我们使用`pyntcloud`库创建一个点云对象,并将点云保存为.PCD文件。 在运行脚本之前,将`input.las`替换为你要转换的.LAS文件路径,将`output.pcd`替换为输出.PCD文件的路径。 这就是用Python将.LAS文件转换为.PCD文件的简单过程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值