0

我正在尝试编写一个简单的文件转换器,将 3d 点云从 LAS 转换为 PCD 文件格式。我正在使用 Ubuntu 16.04。我已经成功编译并安装了 PCL 1.8 和 liblas 1.8.1。我通过编译和运行一个简单的 pcd 教程对此进行了测试,并执行了 lasinfo 以输出给定 las 文件的信息。

我现在想编译其中一个 liblas 教程,但是在我使用任何 liblas 函数的第一行中它失败了。我怀疑这与图书馆的链接有关,但我对此几乎没有任何经验。这是我收到的错误消息:

/home/icedoggy/Documents/QtConsoleTestApp/TestApp/main.cpp:21: error: undefined reference to `liblas::Reader::Reader(std::istream&)' 我得到这个包含 liblas:: .. .

包含目录的路径似乎是正确的,并且当我键入时代码完成工作: liblas:: list of function appears

更新/编辑:更新后的代码现在包含 pcl 和 liblas 头文件并使用这些库。一个 las 文件被读入并保存为 pcd 文件。这可能对其他人有帮助,因此我将其发布在这里。然而,我遇到的问题与源代码无关,而是与 liblas 库包含到 QT 项目中的方式有​​关。我现在已经更改为一个 cmake 项目,下面也提供了 CMakeLists.txt。

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

#include <liblas/liblas.hpp>
#include <fstream>  // std::ifstream

int  main (int argc, char** argv){

pcl::PointCloud<pcl::PointXYZI> cloud;

  // reading data from LAS file:
  // 1) create a file stream object to access the file

std::ifstream ifs;
ifs.open("~/DATASETS/20140320-1-1.las", std::ios::in |     std::ios::binary);

  liblas::ReaderFactory f;  
  liblas::Reader reader = f.CreateWithStream(ifs);

  liblas::Header const& header = reader.GetHeader();

  long int nPts = header.GetPointRecordsCount();
  std::cout << "Compressed: " << (header.Compressed() == true) ? "true\n":"false\n";
  std::cout << "\nSignature: " << header.GetFileSignature() << '\n';
  std::cout << "Points count: " << nPts << '\n';



  // Fill in the PCD cloud data
  cloud.width    = nPts;
  cloud.height   = 1;
  cloud.is_dense = true;
  cloud.points.resize (cloud.width * cloud.height);

  while (reader.ReadNextPoint()){
        liblas::Point const& p = reader.GetPoint();

    cloud.points[i].x = p.GetX();
    cloud.points[i].y = p.GetY();
    cloud.points[i].z = p.GetZ();
    cloud.points[i].intensity = p.GetIntensity();

}

// save data to pcd file in ascii format.
  pcl::io::savePCDFileASCII ("output_in_pcdformat.pcd", cloud);
  std::cerr << "Saved " << cloud.points.size () << " data points ." << std::endl;

   return (0);
}

我用于上述代码的资源是:https ://www.liblas.org/tutorial/cpp.html 和http://pointclouds.org/documentation/tutorials/writing_pcd.php以及https://cmake。 org/cmake-tutorial/用于 cmake(见下文)。

好的,正如一些评论所提到的,我已经改编了这篇文章。我对 cmake 做了一些阅读,因为我不喜欢了解 QT-creator 的细节,因为我的大多数其他项目也是 cmake 项目。我遇到的问题是,我没有在我的 qt 项目中链接 libLAS 库(或者我尝试这样做的方式不起作用)。这就是我用cmake解决问题的方法。带有 ** 的行与我的问题有关。

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(pcd_write)
find_package(PCL 1.7 REQUIRED)
**find_package(libLAS REQUIRED)**
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (pcd_write pcd_write.cpp)
**target_link_libraries (pcd_write ${PCL_LIBRARIES} ${libLAS_LIBRARIES})**
4

0 回答 0