无序点云数据集的空间变换检测

21 篇文章 10 订阅
// 无序点云数据集的空间变换检测

// 

#include "stdafx.h"

#include <pcl/point_cloud.h>
#include <pcl/octree/octree.h>
#include <iostream>
#include <vector>
#include <ctime>


int
main (int argc, char*argv)
{
srand((unsigned int) time(NULL));
//八叉树分辨率,即体素的大小
float resolution = 32.0f;
pcl::octree::OctreePointCloudChangeDetector<pcl::PointXYZ> octree(resolution);
pcl::PointCloud<pcl::PointXYZ> ::Ptr cloudA( new pcl::PointCloud<pcl::PointXYZ>);
//构建点云数据 cloudA
cloudA->width = 128;
cloudA->height = 1;
cloudA->points.resize(cloudA->width * cloudA->height);
for(size_t i = 0; i<cloudA->points.size();++i)
{
cloudA->points[i].x = 64.0f * rand() / (RAND_MAX + 1.0f);
cloudA->points[i].y = 64.0f * rand() / (RAND_MAX + 1.0f);
cloudA->points[i].z = 64.0f * rand() / (RAND_MAX + 1.0f);
}


//添加点云到八叉树,建立八叉树
octree.setInputCloud(cloudA);
octree.addPointsFromInputCloud();
//交换八叉树缓存,
octree.switchBuffers();
//创建点云B
pcl::PointCloud<pcl::PointXYZ> ::Ptr cloudB (new pcl::PointCloud<pcl::PointXYZ>);
cloudB->width = 128;
cloudB->height = 1;
cloudB->resize(cloudB->width * cloudB->height);
for( size_t i = 0; i <cloudB->points.size();++i)
{
cloudB->points[i].x =64.0f* rand () / (RAND_MAX +1.0f);
cloudB->points[i].y =64.0f* rand () / (RAND_MAX +1.0f);
cloudB->points[i].z =64.0f* rand () / (RAND_MAX +1.0f);
}
//添加点云到八叉树
octree.setInputCloud(cloudB);
octree.addPointsFromInputCloud();


std::vector<int > newPointIdxVector;
//获取前一cloudA对应的八叉树在cloudB对应的八叉树中没有的体素
octree.getPointIndicesFromNewVoxels(newPointIdxVector);
//打印输出点
std::cout<<"Output from getPointIndicesFromNewVoxels:"<<std::endl;
for(size_t i = 0;i<newPointIdxVector.size();++i)
{
std::cout<<i<<"# Index:"<< newPointIdxVector[i]<<" Point:"
<<cloudB->points[newPointIdxVector[i]].x<< " "
<<cloudB->points[newPointIdxVector[i]].y<< " "
<<cloudB->points[newPointIdxVector[i]].z<< std::endl;
}
system("pause");
}

reference:朱德海. 点云库PCL学习教程[M]. 北京航空航天大学出版社, 2012.

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值