PCL 点云体素化并求体素中心

算法原理

在这里插入图片描述

代码实现

#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <iostream>
#include <pcl/octree/octree.h>

using namespace std;

typedef std::vector< pcl::PointXYZ, Eigen::aligned_allocator<pcl::PointXYZ> > AlignedPointTVector;   //分配内存对齐Eigen::MatrixXf;
//用来储存计算到的中心点
int main(int argc, char** argv)
{
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::io::loadPCDFile<pcl::PointXYZ>("30m1_C.pcd", *cloud);
	cout << "loading " << cloud->points.size() << " datas from file." << endl;

	//查找体素格的中心
	AlignedPointTVector voxel_center;
	voxel_center.clear();      //初始化
	float resolution = 0.25f;   //设置体素格的边长
	pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree(resolution);
	// int treeDepth_ = octree.getTreeDepth();
	// cout << "the depth of treeDepth_ is : " << treeDepth_ << endl;
	octree.setInputCloud(cloud);
	octree.addPointsFromInputCloud();   
	octree.getOccupiedVoxelCenters(voxel_center);
	// int occupiedVoxelCenters = octree.getOccupiedVoxelCenters(voxel_center);
	// cout << "the number of occupiedVoxelCenters are : " << occupiedVoxelCenters << endl;//输出体素格中心个数
	cout << "the number of voxel are : " << voxel_center.size() << endl;   //输出体素中心的个数

	return 0;
}

相关链接《PCL》点云体素化求其体素中心

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 1024 设计师: 上身试试
应支付0元
点击重新获取
扫码支付

支付成功即可阅读