pcl教程(五)体素可视化

#include
#include <pcl/common/common_headers.h>
#include <pcl/features/normal_3d.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/io/pcd_io.h> //文件输入输出
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/statistical_outlier_removal.h>

using namespace std::chrono_literals;
using namespace std;
int main(int argc, char** argv) {
pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer(“HelloMyFirstVisualPCL”));
viewer->setBackgroundColor(1, 1, 1);

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
if (pcl::io::loadPCDFile<pcl::PointXYZ>("E:\\github\\gitwork\\rc1\\rabbit.pcd", *cloud) == -1)
{
	PCL_ERROR("Cloudn't read file!");
	return -1;
}
cout << "there are " << cloud->points.size() << " points before filtering." << endl;

//FILE*fp = NULL; fp = fopen("el.txt", "r");	//2DpointDatas.txt
//if (!fp)
//{
//	printf("打开文件失败!!\n");
//	int m;
//	cin >> m;
//	exit(0);
//}
float x = 0.1f, y = 0.1f, z = 0.1f;
//int i = 0;

pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> fildColor(cloud, "z"); // 按照z字段进行渲染
//viewer->addPointCloud(cloud);
viewer->addPointCloud<pcl::PointXYZ>(cloud, fildColor, "sample cloud");


//pcl::PCLPointCloud2::Ptr cloud_in2(new pcl::PCLPointCloud2());
//pcl::PCLPointCloud2::Ptr cloud_filtered(new pcl::PCLPointCloud2());
//pcl::toPCLPointCloud2(*cloud, *cloud_in2);
//pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
//sor.setInputCloud(cloud_in2);
    sor.setLeafSize(0.1f,0.1f,0.1f);
//sor.setLeafSize(1.0f, 1.0f, 1.0f);
//sor.filter(*cloud_filtered);
//cloud->clear();
//pcl::fromPCLPointCloud2(*cloud_filtered, *cloud);


int i = 0;
int icount = cloud->points.size();
icount = 3000;
while (i< (icount-10))
{
	float voxel = 0.001f;


	//fscanf(fp, "%f %f %f", &x, &y, &z);
    x = cloud->points.at(i).x;
	y = cloud->points.at(i).y;
	z = cloud->points.at(i).z;


	string cube = "cube" + to_string(i);
	float x_min = floor(x / voxel)*voxel;
	float x_max = floor(x / voxel)*voxel + voxel;
	float y_min = floor(y / voxel)*voxel;
	float y_max = floor(y / voxel)*voxel + voxel;
	float z_min = floor(z / voxel)*voxel;
	float z_max = floor(z / voxel)*voxel + voxel;
	double r = 1.0, g = 0.5, b = 0.5;
	viewer->addCube(x_min, x_max, y_min, y_max, z_min, z_max, r, g, b, cube);
	viewer->setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_REPRESENTATION, pcl::visualization::PCL_VISUALIZER_REPRESENTATION_WIREFRAME, cube);

	i++;
}
while (!viewer->wasStopped())
{
	viewer->spinOnce(100);
	std::this_thread::sleep_for(100ms);
}
return 0;

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PCL是点云(Point Cloud Library)的缩写,它提供了许多用于处理、分析和可视化点云数据的功能。将点云转换为深度图可以通过PCL中的一些功能实现。 在PCL中,将点云转换为深度图可以通过以下步骤实现: 1. 加载点云数据:首先,需要使用PCL中的PointCloud类来加载点云数据。点云数据可以来自多种来源,如激光雷达、深度相机等。可以使用PCL提供的方法读取和解析点云数据。 2. 点云降采样:如果点云数据较大,可以先对点云进行降采样,以减少计算量和内存使用。PCL提供了多种点云降采样的方法,如体素网格滤波、统计滤波等。这些方法可以对点云进行过滤,只保留一部分点云,这样可以简后续的处理步骤。 3. 点云转换为深度图:一旦点云数据准备好,可以使用PCL提供的Projection类来将点云转换为深度图。Projection类提供了将点云数据投影到给定分辨率的深度图像中的方法。通过将点云数据映射到深度图像中,可以获得每个像素位置对应的深度值。 4. 可视化或保存深度图:最后,我们可以选择将深度图可视化或保存为图像文件。PCL提供了可视化和图像保存的方法,可以将深度图像显示在屏幕上或保存为文件。 总结起来,通过PCL提供的功能,可以方便地将点云数据转换为深度图。这为进一步的点云分析和处理提供了更多的可能性。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值