open3d读取、显示和保存点云数据

1、从文件中读取点云

接口1

bool open3d::io::ReadPointCloud	(	const std::string & 	filename,
geometry::PointCloud & 	pointcloud,
const ReadPointCloudOption & 	params = {} 
)	

接口2

bool open3d::io::ReadPointCloud	(	const std::string & 	filename,
geometry::PointCloud & 	pointcloud,
const std::string & 	file_format,
bool 	remove_nan_points,
bool 	remove_infinite_points,
bool 	print_progress 
)	

接口3

从扩展名中读取点云

bool open3d::io::ReadPointCloudFromPCD	(	const std::string & 	filename,
geometry::PointCloud & 	pointcloud,
const ReadPointCloudOption & 	params 
)	

bool open3d::io::ReadPointCloudFromPLY	(	const std::string & 	filename,
geometry::PointCloud & 	pointcloud,
const ReadPointCloudOption & 	params 

2、保存点云

WritePointCloud()

bool open3d::io::WritePointCloud	(	const std::string & 	filename,
const geometry::PointCloud & 	pointcloud,
const WritePointCloudOption & 	params = {} 
)	

bool open3d::io::WritePointCloud	(	const std::string & 	filename,
const geometry::PointCloud & 	pointcloud,
bool 	write_ascii,
bool 	compressed,
bool 	print_progress 
)		

// 扩展名保存
bool open3d::io::WritePointCloudToPCD	(	const std::string & 	filename,
const geometry::PointCloud & 	pointcloud,
const WritePointCloudOption & 	params 
)		

bool open3d::io::WritePointCloudToPLY	(	const std::string & 	filename,
const geometry::PointCloud & 	pointcloud,
const WritePointCloudOption & 	params 
)	

3、读取点云

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

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

	std::string fileName("bunny.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;
}

读取txt格式点云

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

int main(int argc, char* argv[])
{
	std::string fileName("bunny.txt");
	auto cloud_ptr = std::make_shared<open3d::geometry::PointCloud>();
	if (open3d::io::ReadPointCloudFromXYZ(fileName, *cloud_ptr, {"xyz"}) == 0)
	{// 或者用open3d::io::ReadPointCloud(fileName, *cloud_ptr, { "xyz" });
		
		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;
}

4、显示点云

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

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

	
	auto source = std::make_shared<open3d::geometry::PointCloud>();
	if (open3d::io::ReadPointCloud("1.pcd", *source) == 0)
	{
		open3d::utility::LogWarning("点云读取失败!!!\n");
		return -1;
	}
	if(source->HasNormals())
	source->NormalizeNormals(); // 将法向量归一化到1

	auto target = std::make_shared<open3d::geometry::PointCloud>();
	if (open3d::io::ReadPointCloud("2.pcd", *target) == 0)
	{
		open3d::utility::LogWarning("点云读取失败!!!\n\n");
		return -1;
	}
	if (target->HasNormals())
		target->NormalizeNormals(); // 将法向量归一化到1
	Eigen::Vector3d color{ 0.0,0.0,1.0 };
	target->PaintUniformColor(color);
	open3d::visualization::DrawGeometries({ source ,target }, "PointCloud", 1600, 900);

	return 0;
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jsxhn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值