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 
#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++;
	}
	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})

参考链接

你可能感兴趣的:(三维点云,ubuntu,linux)