ubuntu 16.04使用liblas库读取las格式点云

ubuntu 16.04使用liblas库读取las格式点云

liblas库的安装与使用

liblas库是一个对Lidar数据.las格式的读写等操作的开源库。
下载liblas软件源码:https://liblas.org/download.html
如下该是liblas 1.8.1版本
链接:https://pan.baidu.com/s/1-BcfrR1v8d5NZQTgbfOPJg
提取码:7joh

***.tar.gz文件解压

tar -xzvf *****.tar.gz

liblas安装

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

检查安装是否成功

lasinfo ***.las

可能会遇到的问题:
1、Unable to find sufficient GeoTIFF
解决方法:安装libgeotiff
如下该是libgeotiff-1.3.0版本安装包
链接: https://pan.baidu.com/s/10vy5OytkJB6V9U5u7ELBjw 提取码: fsau

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

.las点云数据的读取

程序:las_read.cpp

#include 
#include 
#include 
#include 
#include 
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++;
	}
	return 0;
}
	//==================================================================

保存为.pcd 格式的点云

pcl::io::savePCDFile("***.pcd",cloud);

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})

你可能感兴趣的:(pcl,lablas,cmake,ubuntu,c++)