Open3D和PCL都是很优秀的三维数据处理库,但是,它们不支持.las文件。(作为处理大/自然场景LAS点云的我,心情有点不美丽。)PCL作为较早的库,算法较多,对C++支持较多;Open3D作为新库,算法不如PCL多,个人感觉它对Python支持较好,可视化效果较好。

一、配置环境

两种方式

1.1 CMake

用 CMakeLists.txt,加上 Eigen 的相关内容就可以。可参考官方文档 Open3D的C++ CmakeList.txt

1.2 VS配置

Open3D获取点云信息,需要 Eigen。

(1)右击工程—属性—VC++目录—包含目录,添加如下路径:

配置属性-链接器-输入-附件依赖项,添加如下路径:

配置属性-链接器-输入-附件依赖项,添加如下:

Open3D.lib
opengl32.lib
glu32.lib
glew.lib
glfw3.lib
turbojpeg-static.lib
jsoncpp.lib
png.lib
zlib.lib
tinyfiledialogs.lib
tinyobjloader.lib
qhullcpp.lib
qhullstatic_r.lib
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
comdlg32.lib
advapi32.lib

二、分享给有需要的人,代码质量勿喷

//Open3D
#include "Open3D/Open3D.h"

//Eigen
#include "Eigen/Dense"


void testOpen3D::xjGetInformation(const QString &pcPath)
{
	/* read PC */
	auto cloud_ptr = std::make_shared<open3d::geometry::PointCloud>();
	if (!open3d::io::ReadPointCloud(pcPath.toStdString(), *cloud_ptr)) { return; }

	//点数
	int pointCount = cloud_ptr->points_.size();
	ui.listWidget->addItem("点数:" + QString::number(pointCount));

	//包围盒
	Eigen::Vector3d min_bound = cloud_ptr->GetMinBound();
	double minX = min_bound(0);
	double minY = min_bound(1);
	double minZ = min_bound(2);
	ui.listWidget->addItem("minX = " + QString::number(minX, 'f', 4) + 
            ", minY = " + QString::number(minY, 'f', 4) + ", minZ = " + QString::number(minZ, 'f', 4));
	Eigen::Vector3d max_bound = cloud_ptr->GetMaxBound();
	double maxX = max_bound(0);
	double maxY = max_bound(1);
	double maxZ = max_bound(2);
	ui.listWidget->addItem("maxX = " + QString::number(maxX, 'f', 4) + 
            ", maxY = " + QString::number(maxY, 'f', 4) + ", maxZ = " + QString::number(maxZ, 'f', 4));

	//单点信息
	double x = 0, y = 0, z = 0;
	for (int i = 0; i < cloud_ptr->points_.size(); i++)
	{
		const Eigen::Vector3d &point = cloud_ptr->points_[i];
		x = point(0);
		y = point(1);
		z = point(2);
		ui.listWidget->addItem("pID="+ QString::number(i)+ ", x = " + QString::number(x, 'f', 4) + 
                    ", y = " + QString::number(y, 'f', 4) + ", Z = " + QString::number(z, 'f', 4));
	}

	/* visualize PC */
	open3d::visualization::DrawGeometries({ cloud_ptr });

	/* write PC */
	open3d::geometry::PointCloud outputPC;
	for (int i = 0; i < 360; i++)
	{
		outputPC.points_.push_back(Eigen::Vector3d(cos(i), sin(i), cos(i)*sin(i)));
	}
	if (open3d::io::WritePointCloud("F:/outputPC.pcd", outputPC))
	{
		QMessageBox::information(0, "", "OK");
	}
}

三、结果

3.1 点云信息

3.2 点云可视化 

3.3 生成的点云 

四、参考资料

https://github.com/intel-isl/Open3D/blob/master/examples/cpp/PointCloud.cpp

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐