PCL學習筆記——利用Octree找出存在於點雲B中,不存在點雲A中的點
阿新 • • 發佈:2018-11-11
resolution——八叉樹解析度,即最小體素的邊長(畫素單位)
getPointIndicesFromNewVoxels() —— 從前一個緩衝區中不存在的所有葉節點獲取索引
switchBuffers()——交換八叉樹快取,但是先前點雲對應的八叉樹結構仍在記憶體中
// pointclouds_octree.cpp: 定義控制檯應用程式的入口點。 // #include "stdafx.h" #include<iostream> #include<fstream> #include<opencv.hpp> #include<pcl/io/pcd_io.h> #include<pcl/point_types.h> #include<pcl/octree/octree.h> using namespace std; using namespace cv; int main() { fstream file_name1, file_name2; ofstream differ; differ.open("differ.txt"); file_name1.open("Result3D_end42.txt"); file_name2.open("Result3D_end52.txt"); pcl::PointCloud<pcl::PointXYZ> cloudA; pcl::PointCloud<pcl::PointXYZ> cloudB; cloudA.width = 230088; cloudA.height = 1; cloudA.is_dense = false; cloudA.points.resize (cloudA.width*cloudA.height); cloudB.width = 250025; cloudB.height = 1; cloudB.is_dense = false; //點雲密度,非密集型 cloudB.points.resize (cloudB.width*cloudB.height); Vec3d dd; for (size_t i = 0; i < cloudA.points.size(); i++) { file_name1 >> dd[0]; file_name1 >> dd[1]; file_name1 >> dd[2]; cloudA.points[i].x = (double)dd[0]; cloudA.points[i].y = (double)dd[1]; cloudA.points[i].z = (double)dd[2]; } for (size_t j = 0; j < cloudB.points.size(); j++) { file_name2 >> dd[0]; file_name2 >> dd[1]; file_name2 >> dd[2]; cloudB.points[j].x = (double)dd[0]; cloudB.points[j].y = (double)dd[1]; cloudB.points[j].z = (double)dd[2]; } float resolution = 10.0f; //八叉樹解析度,即最小體素的邊長 //pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree(resolution); //初始化octree pcl::octree::OctreePointCloudChangeDetector<pcl::PointXYZ>octree(resolution); //初始化空間變化檢測物件 //新增cloudA到八叉樹中 octree.setInputCloud(cloudA.makeShared()); octree.addPointsFromInputCloud(); octree.switchBuffers(); //交換八叉樹快取,但是coludA對應的八叉樹結構仍在記憶體中 //新增cloudB到八叉樹中 octree.setInputCloud(cloudB.makeShared()); octree.addPointsFromInputCloud(); vector<int>newPointIdxVector; //儲存新加入點索引的向量 octree.getPointIndicesFromNewVoxels(newPointIdxVector); for (size_t i = 0; i < newPointIdxVector.size(); i++) { differ << cloudB.points[newPointIdxVector[i]].x << " " << cloudB.points[newPointIdxVector[i]].y << " " << cloudB.points[newPointIdxVector[i]].z <<" "<< endl; } file_name1, file_name2, differ.close(); return 0; }
目前還不知道如何利用PCL求取兩片點雲的重疊區域!!!
實現效果在Geomagic下的展示如下:
附:
銀色是CloudB中的點,黑色是CloudA中的點,綠色點是檢測出來B中新增加不屬於A的結果點。