官网的教程中有一个octree的例子,可以实现这个功能
https://pcl.readthedocs.io/projects/tutorials/en/latest/octree_change.html#octree-change-detection
例子中能检测出点云B在点云A上增加的点,但不能检测出减少的点,如果A为背景,B为包含背景和其他物体的点云,那么可以实现在B中去背景的作用,下面的代码对官网的代码做了简单的修改,B的前100个点和A近似相同,后面的是新加的不同的点,结果后面的点都检测出来了。当然前提条件是两个点云坐标系相同,否则需要先做配准。,在配准的时候也可以直接求交集,见本文最后。
// modified from the code in https://pcl.readthedocs.io/projects/tutorials/en/latest/octree_change.html#octree-change-detection
#include <pcl/point_cloud.h>
#include <pcl/octree/octree_pointcloud_changedetector.h>
#include <iostream>
#include <vector>
#include <ctime>
int
main (int argc, char** argv)
{
srand ((unsigned int) time (NULL));
// Octree resolution - side length of octree voxels
float resolution = 32.0f;
// Instantiate octree-based point cloud change detection class
pcl::octree::OctreePointCloudChangeDetector<pcl::PointXYZ> octree (resolution);