ubuntu 编译使用 liblas 读取点云

在ubuntu上使用las读取点云

1、环境配置

1.1、安装libgeotiff

下载依赖

sudo apt-get install libtiff-dev  //安装libtiff
sudo apt-get install libproj-dev  //安装libproj

下载源码,编译
如下该是libgeotiff-1.3.0版本安装包

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

1.2、liblas安装

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

1.3、测试liblas

las_read.cpp

#include <iostream>
#include <liblas/liblas.hpp>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
using namespace std;
int main(int argc,char **argv)
{
   
	//----------------------------- 打开LAS格式点云文件并读取 ----------------------------
	std::ifstream ifs("****.las", std::ios::in | std::ios::binary); 
     if (!ifs.is_open())
    {
   
        std::cout << "cannot open .las" << std::endl;
        return (0);
    }
	liblas::ReaderFactory f;
	liblas::Reader reader = f.CreateWithStream(ifs); 

	//读取LAS文件信息头
	liblas::Header const& header = reader.GetHeader();
	double maxX = header.GetMaxX();
	double minX = header.GetMinX();
	double maxY = header.GetMaxY();
	double minY = header.GetMinY();
	double maxZ = header.GetMaxZ();
	double minZ = header.GetMinZ();
	int nbPoints = header.GetPointRecordsCount();
	string signature = header.GetFileSignature();

	cout << "maxX: " << maxX << endl;
	cout << "minX: " << minX << endl;
	cout << "maxY: " << maxY << endl;
	cout << "minY: " << minY << endl;
	cout << "maxZ: " << maxZ << endl;
	cout << "minZ: " << minZ << endl;
	cout << "点个数: " << maxX << endl;
	cout << "signature: " << signature << endl;

	pcl::PointCloud<pcl::PointXYZRGB> cloud;
	cloud.width = nbPoints;	
	cloud.height = 1;
	cloud.is_dense = false;
	cloud.points.resize(cloud.width * cloud.height);
	
	int i = 0;
	uint16_t r1, g1, b1;
	int r2, g2, b2;
	uint32_t rgb;

	//读取点云坐标和色彩信息
	while (reader.ReadNextPoint())
	{
   
		// 获取las数据的x,y,z信息
		cloud.points[i].x = reader.GetPoint().GetX();
		cloud.points[i].y = reader.GetPoint().GetY();
		cloud.points[i].z = reader.GetPoint().GetZ();
		
		// 获取las数据的r,g,b信息
		r1 = reader.GetPoint().GetColor().GetRed();
		g1 = reader.GetPoint().GetColor().GetGreen();
		b1 = reader.GetPoint().GetColor().GetBlue();
		r2 = ceil(((float)r1 / 65536)*(float)256);
		g2 = ceil(((float)g1 / 65536)*(float)256);
		b2 = ceil(((float)b1 / 65536)*(float)256);
		rgb = ((int)r2) << 16 | ((int)g2) << 8 | ((int)b2);
		cloud.points[i].rgb = *reinterpret_cast<float*>(&rgb);
		i++;
	}
	pcl::io::savePCDFile("***.pcd",cloud);

	return 0;
}
	//==================================================================

CMakeLists.txt 文件

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(LasRead)

find_package(PCL 1.8 REQUIRED)
find_package(libLAS REQUIRED)

include_directories(${
   PCL_INCLUDE_DIRS})
#或者指定搜寻pcl路径
#include_directories("/usr/include/pcl-1.8")

link_directories(${
   PCL_LIBRARY_DIRS})
add_definitions(${
   PCL_DEFINITIONS})

add_executable (las_read las_read.cpp)
target_link_libraries (las_read ${
   PCL_LIBRARIES} ${
   libLAS_LIBRARIES})

参考链接

相关推荐

  1. ubuntu 编译使用 liblas 读取

    2024-01-28 01:36:02       66 阅读
  2. 使用CloudCompare计算曲率 - 编程指南

    2024-01-28 01:36:02       68 阅读
  3. ubuntu thrift 编译使用

    2024-01-28 01:36:02       33 阅读
  4. ubuntu使用ndk编译libevnet

    2024-01-28 01:36:02       31 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-28 01:36:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-28 01:36:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-28 01:36:02       82 阅读
  4. Python语言-面向对象

    2024-01-28 01:36:02       91 阅读

热门阅读

  1. Scikit-Learn 高级教程——高级特征工程

    2024-01-28 01:36:02       57 阅读
  2. 【算法题】67. 二进制求和

    2024-01-28 01:36:02       53 阅读
  3. Unity UIBasePanel 简单的ui基类

    2024-01-28 01:36:02       57 阅读
  4. uniapp - editor 富文本的使用

    2024-01-28 01:36:02       50 阅读
  5. c#反射用法

    2024-01-28 01:36:02       55 阅读
  6. Compose | UI组件(一) | Modifier修饰符

    2024-01-28 01:36:02       63 阅读
  7. python脚本加密

    2024-01-28 01:36:02       48 阅读
  8. 二分查找的不同实现方法和总结

    2024-01-28 01:36:02       55 阅读
  9. Chrome 浏览器插件 runtime 字段解析

    2024-01-28 01:36:02       50 阅读
  10. C语言运算符

    2024-01-28 01:36:02       55 阅读