PCL体素化降采样 实现立方体体素可视化
PCL体素化降采样 实现立方体体素可视化
- PCL库函数自带的VoxelGrid类能够实现对点云进行降采样。基本原理是对点云进行网格划分,落在每个小立方块区域中的点的重心就代表网格中的所有点。因此通过控制网格边长就能够控制降采样的点数。缺点在于不能指定降采样点数大小,只能通过调参逼近。
- 具体的体素化代码实现不做介绍,可以参考以下博客:
体素栅格滤波(下采样) - 以下代码功能是可视化立方体体素
- 目前没有实现改变体素颜色,后期视使用情况增添(版本二)
#include <thread>
#include <pcl/common/common_headers.h>
#include <pcl/features/normal_3d.h>
#include <pcl/visualization/pcl_visualizer.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);FILE*fp = NULL; fp = fopen("filename.txt", "r"); //2DpointDatas.txtif (!fp){printf("打开文件失败!!\n");int m;cin >> m;exit(0);}float x = 0, y = 0, z = 0;int i = 0;while (!feof(fp)){float voxel = 0.82;i++;fscanf(fp, "%f %f %f", &x, &y, &z);Eigen::Vector3f center(floor(x / voxel)*voxel + voxel/2, floor(y / voxel)*voxel + voxel/2, floor(z / voxel)*voxel + voxel/2);Eigen::Quaternionf rotation(1, 0, 0, 0);string cube = "cube" + to_string(i);viewer->addCube(center, rotation, voxel, voxel, voxel, cube);}while (!viewer->wasStopped()){viewer->spinOnce(100);std::this_thread::sleep_for(100ms);}return 0;
}
版本二
- 加入点线框和改变点和线框的颜色
- 可以将两个读入改为一个此处就不修改了
#include <thread>
#include <pcl/common/common_headers.h>
#include <pcl/features/normal_3d.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/io/pcd_io.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>("el.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.txtif (!fp){printf("打开文件失败!!\n");int m;cin >> m;exit(0);}float x = 0, y = 0, z = 0;int i = 0;pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> fildColor(cloud, "z"); // 按照z字段进行渲染//viewer->addPointCloud(cloud);viewer->addPointCloud<pcl::PointXYZ>(cloud, fildColor, "sample cloud");while (!feof(fp)){float voxel = 1.85;i++;fscanf(fp, "%f %f %f", &x, &y, &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 = 0.5, 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);}while (!viewer->wasStopped()){viewer->spinOnce(100);std::this_thread::sleep_for(100ms);}return 0;
}
PCL体素化降采样 实现立方体体素可视化相关推荐
- 利用PCL点云下采样实现数据体素化
利用PCL点云下采样实现数据体素化 PCL PCL(Point Cloud Library) 库集成了针对大体量级别的空间点数据处理所需要的算法和操作,降低了处理相关需求的复杂度,对快速建立点云数据文 ...
- 深度学习: pooling (池化 / 降采样)
在知乎上面看到一个关于池化的神解释,摘来: 池化=涨水 卷积的目的是为了得到物体的边缘形状可以想象水要了解山立体的形状 水位低时得出山脚的形状 水位中等时得出山腰的形状 水位高时得出山顶的形状三点就可 ...
- 点云降采样--ApproximateVoxelGrid点云降采样
1.版本要求 版本: >PCL1.0 2.简介 ApproximateVoxelGrid体素降采样是PCL开源库中非常有效的点云降采样手段.ApproximateVoxelGrid对点云进行体素 ...
- 点云降采样(DownSampling)
点云降采样 1 概述 三维点云往往包含大量冗余数据,直接处理计算量大,消耗时间长,因此对其进行降采样是十分必要的.降采样同时也是点云预处理过程中的关键环节. 2 常用方法 2.1 体素网格下采样 2. ...
- 基于体素化方法的点云降采样
前两天做了一个点云降采样的项目,用pcl自带的降采样方法出来的结果不是很理想,于是就自己写了一个.为了使代码执行效率高点就采用了基于点云索引的方式. 本文使用的方法为:首先,计算点云群的Boundin ...
- 三维点云学习(1)下-点云体素降采样
三维点云学习(1)下 点云体素降采样(Voxel Filter Downsampling) 代码参考网址秦乐乐CSDN博客 理论参考知乎博主:WALL-E 1.方法 Centroid 均值采样 Ran ...
- pcl 中的滤波与降采样
目录 pcl filter模块 RandomSample UniformSampling VoxelGrid StatisticalOutlierRemoval filter 应用 参考 完 pcl ...
- Open3d学习计划—高级篇 6(体素化)
Open3D是一个开源库,支持快速开发和处理3D数据.Open3D在c++和Python中公开了一组精心选择的数据结构和算法.后端是高度优化的,并且是为并行化而设置的. 本系列学习计划有Blue同学作 ...
- Python 三维网格体素化
本文主要是实现将一个网格模型体素化,实现不同分辨率的体素化效果,并且可视化输出为obj文件!首先利用trimesh对mesh进行采样,然后根据采样点得到各个体素点的占有值. 效果 通过调整分辨率以及采 ...
最新文章
- 利用人工智能进行网页设计的10种方法
- mysql存储过程-汇总学习
- MySQL在登陆时出现ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)错误...
- mysql的分页怎么不对_mysql一对多关联查询分页错误问题的解决方法
- elasticSearch6源码分析(1)启动过程
- 重磅!GitHub发布开源负载均衡组件GLB
- aes c# java_AES加密,C#和java相同
- 2015蓝桥杯省赛---java---B---7(牌型种数)
- C++中类和对象的一些注意事项 --- 多态
- 拼装机器人感想_机器人心得体会(20190510062147)
- sqlyog如何设置.时提示字段名_Spring boot 中使用 Tomcat时 用户名 密码如何设置呢?...
- Python布局管理器
- Hibernate,JPA注解@Embeddable
- JAVA Eclipse创建Android程序界面不显示怎么办
- 高校学籍管理系统(SQL Server数据库课程设计)
- RFM用户分层模型|原理+Python全流程实现
- Unity3D--学习太空射击游戏制作(二)
- 由于找不到iutils.dll无法继续执行代码?
- 起码数学常识凸显中学数学的重大错误0
- 土豪聪要请客(stol)