【点云处理】K-means聚类算法在点云数据精简上的应用

我们通过深度相机获取的物体点云数据十分庞大,对后续的点云数据预处理需要大量的计算时间,而传统的体素网格法算法简单,但是对于物体的细节部分不能很好的保留。

我把整个程序分成了两个部分,精简的效果还是不错的,程序太长就不上图了。

一:设置体素大小,提取点云体素中心

#include<iostream>
#include<pcl/visualization/pcl_visualizer.h>
#include<pcl/visualization/cloud_viewer.h>
#include<pcl/octree/octree.h>
#include<pcl/io/pcd_io.h>
#include<vector>
using namespace std;
typedef Eigen::aligned_allocator<pcl::PointXYZ> AlignedPointT;
typedef pcl::PointXYZ PointT;
int main()
{
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::io::loadPCDFile("C:\\Users\\15390\\Desktop\\horse实验结果\\horse.pcd", *cloud);
	float resolution = 0.002; //体素的大小
	cout << "before点云" << cloud->points.size() << endl;
	pcl::octree::OctreePointCloud<pcl::PointXYZ> octree(resolution);
	octree.setInputCloud(cloud);
	octree.addPointsFromInputCloud();
	vector<PointT, AlignedPointT> voxel_centers;
	octree.getOccupiedVoxelCenters(voxel_centers);
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_core(new pcl::PointCloud<pcl::PointXYZ>);
	cloud_core->width = voxel_centers.size();
	cloud_core->height = 1;
	cloud_core->points.resize(cloud_core->height*cloud_core->width);
	for (size_t i = 0; i < voxel_centers.size() - 1; i++)
	{
		cloud_core->points[i].x = voxel_centers[i].x;
		cloud_core->points[i].y = voxel_centers[i].y;
		cloud_core->points[i].z = voxel_centers[i].z;
	}
	pcl::PCDWriter writer;
	writer.write("C:\\User
评论 32
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值