OctreePointCloud类型的setInputCloud方法只是赋值,不会做任何reset。
inline void setInputCloud (const PointCloudConstPtr &cloud_arg,
const IndicesConstPtr &indices_arg = IndicesConstPtr ())
{
input_ = cloud_arg;
indices_ = indices_arg;
}
所以,方法addPointsFromInputCloud可以重复调用。
OctreePointCloudDensity用于计算空间网格的密度。
实际上只是对叶节点进行计数。它的container类型是OctreePointCloudDensityContainer。
/** \brief Read input data. Only an internal counter is increased.
*/
void addPointIndex (int)
{
point_counter_++;
}
这个函数的调用路径是:OctreePointCloud::addPointsFromInputCloud
->OctreePointCloud::addPointIdx
->LeafContainerT::addPointIdx
。
因此,可以逐帧累加,静止的背景所在的网格点的密度会越来越高。对于新的点云,只要检查每个点对应的密度,就可以判断这个点是前景还是背景。
PointCloudColor::const_iterator cloud_it = cloud->begin();
PointCloudColor::const_iterator cloud_it_end = cloud->end();
for (; cloud_it != cloud_it_end; ++cloud_it) {
pcl::PointXYZRGBA pt = *cloud_it;
uint64_t density = oct.getVoxelDensityAtPoint(*cloud_it);
if (density > 2) {
pt.rgba = 0xFFFF0000;
} else if (density > 1) {
pt.rgba = 0xFF00FF00;
} else {
pt.rgba = 0xFF0000FF;
}
display_cloud->points.push_back(pt);
}
伪代码:
read cloud;
octree_density.add(new cloud);
update density threshold;
for point in new cloud:
if octree_density.density_at(point) > threshold:
remove point from cloud;
使用八叉树对背景建好模型之后,这个八叉树的数据结构如何保存呢?
我是用了serializeTree和deserializeTree的方法,但是不成功。
想问一下,你这块是怎么操作的?