Use octree to detect whether the point cloud has changed

Detecting spatial variation between point cloud datasets has several uses:

  1. Target tracking and object recognition: Spatial change detection can be used to update the position, attitude, shape and other information of objects in point cloud data in real time. This is very important for target tracking and object recognition, and can help us accurately identify and track objects in dynamic scenes, thereby achieving intelligent perception and decision-making.

  2. Environmental monitoring and security early warning: In applications that require real-time monitoring of environmental changes, spatial change detection can help us quickly discover and detect abnormalities in the environment. For example, in fields such as security monitoring and industrial production, by detecting spatial changes in point cloud datasets, we can discover possible risks and hidden dangers in time and take measures to ensure safety.

  3. Map update and scene modeling: In the application of map construction or scene modeling, change detection of point cloud datasets can help us update maps or scene models to reflect changes in the actual environment. For example, in the construction site or urban renewal process, detecting and responding to spatial changes in time can effectively improve the accuracy and practicality of maps and models.

  4. Quality control and data processing: In the process of point cloud data acquisition and processing, there may be problems such as noise, incompleteness or distortion. Through spatial change detection, we can help us eliminate or correct these problems and improve the quality and accuracy of point cloud data.

In summary, detecting spatial variation between point cloud datasets has a wide range of applications, including target tracking and object recognition, environmental monitoring and safety warning, map updating and scene modeling, as well as quality control and data processing. By accurately detecting and responding to spatial changes, it can help us better understand and utilize point cloud data for smarter and more precise applications.

Differences with Point Cloud Connections

Point cloud connection refers to the registration and fusion of multiple point cloud datasets to generate a more complete and accurate point cloud model. It usually involves technologies such as point cloud rigid body transformation, similarity measure and optimization algorithm, aiming to find the best registration transformation parameters so that the corresponding points between different point clouds can best overlap.

Spatial change detection refers to comparing the differences and changes between two point cloud datasets to detect new, deleted or moved points between point cloud datasets. It pays more attention to the dynamic changes of point cloud datasets rather than the accuracy of point cloud registration.

Point cloud change detection usually consumes relatively few resources compared to point cloud connection. Point cloud change detection only needs to compare the coordinates or attributes of points by comparing the differences between two point clouds. This comparison process is relatively simple and does not require complex mathematical operations or iterative optimization.

Octree buffer

During the processing of point cloud data, the octree needs to maintain two buffers , one for storing the current point cloud data and the other for storing the last point cloud data . By switching the buffer, the previous point cloud data can be retained when new point cloud data is added next time, so as to detect spatial changes.

Specifically, switchBuffers()the function will exchange the current point cloud data buffer with the previous point cloud data buffer. In this way, when adding new point cloud data, the octree will store the new point cloud data in the current buffer, and store the last point cloud data in another buffer for subsequent space Change detection.

To sum up, octree.switchBuffers()the function is to exchange the current point cloud data buffer with the last point cloud data buffer, so as to add the next point cloud data and detect the spatial change.

detection code

#include <pcl/point_cloud.h>
#include <pcl/octree/octree.h>

#include <iostream>
#include <vector>
#include <ctime>


int main(){
    srand((unsigned int)time(NULL));

    // 创建一个分辨率为32.0的pcl::octree::OctreePointCloudChangeDetector八叉树对象
    // 用于检测点云数据之间的变化
    float resolution = 32.0f;
    pcl::octree::OctreePointCloudChangeDetector<pcl::PointXYZ> octree(resolution);

    // 一个点云,cloudA
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloudA(new pcl::PointCloud<pcl::PointXYZ>);

    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);

    }

    // 点云coudA设置为八叉树的输入
    octree.setInputCloud(cloudA);
    octree.addPointsFromInputCloud();

    // 切换到八叉树缓冲区
    octree.switchBuffers();

    // 另一个点云,cloudB
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloudB(new pcl::PointCloud<pcl::PointXYZ>);

    cloudB->width = 128;
    cloudB->height = 1;
    cloudB->points.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);
    }

    // 点云cloudB设置为八叉树的输入
    octree.setInputCloud(cloudB);
    octree.addPointsFromInputCloud();

    // 创建一个整型向量,用于存储八叉树中新增的点的索引
    std::vector<int> newPointIdxVector;

    // 获取新增点的索引
    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;



}

Guess you like

Origin blog.csdn.net/weixin_45824067/article/details/131480181