C++ 【 Open3D 】 读取、可视化并保存点云

发布于:2024-07-10 ⋅ 阅读:(179) ⋅ 点赞:(0)

一、读取常见点云

#include <iostream>
#include <Open3D/Open3D.h>

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

	std::string fileName("hand.pcd");
	auto cloud_ptr = std::make_shared<open3d::geometry::PointCloud>();
	if (open3d::io::ReadPointCloud(fileName, *cloud_ptr) == 0)
	{
		open3d::utility::LogWarning("Failed to read {}\n\n", fileName);
		return -1;
	}

	cloud_ptr->NormalizeNormals(); // 将法向量归一化到1
	open3d::visualization::DrawGeometries({ cloud_ptr }, "PointCloud", 1600, 900);
	open3d::io::WritePointCloudToPCD("bunny1.pcd", *cloud_ptr, false);

	return 0;
}

请添加图片描述
二、显示点云自己颜色

#include <iostream>
#include <Open3D/Open3D.h>

using namespace std;

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

	auto cloud = std::make_shared<open3d::geometry::PointCloud>();
	// tree.pcd自身带有RGB颜色
	if (open3d::io::ReadPointCloud("Armadillo.pcd", *cloud) == 0)
	{
		open3d::utility::LogWarning("点云读取失败!!!\n\n");
		return -1;
	}
	cout << "从点云数据中读取" << cloud->points_.size() << "个点" << endl;

	if (cloud->HasNormals())
		cloud->NormalizeNormals(); // 将法向量归一化到1

	open3d::visualization::DrawGeometries({ cloud }, "PointCloud", 1600, 900);
	open3d::io::WritePointCloudToPCD("Armadillo.pcd", *cloud, false);
	return 0;
}

请添加图片描述


网站公告

今日签到

点亮在社区的每一天
去签到