日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

PCL点云库:Kd树

發布時間:2025/6/15 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PCL点云库:Kd树 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  Kd樹按空間劃分生成葉子節點,各個葉子節點里存放點數據,其可以按半徑搜索或鄰區搜索。PCL中的Kd tree的基礎數據結構使用了FLANN以便可以快速的進行鄰區搜索。FLANN?is a library for performing fast approximate nearest neighbor searches in high dimensional spaces。下面是一個最基本的例子,只尋找一個最近點:

#include <pcl/point_cloud.h> #include <pcl/kdtree/kdtree_flann.h>#include <iostream> #include <vector> #include <ctime>int main (int argc, char** argv) {srand (time (NULL)); //seeds rand() with the system time time_t begin,end;begin = clock(); //開始計時//-------------------------------------------------------------------------------pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);// Generate pointcloud datacloud->width = 400000;cloud->height = 1;cloud->points.resize (cloud->width * cloud->height);// fills a PointCloud with random datafor (size_t i = 0; i < cloud->points.size (); ++i){cloud->points[i].x = 1024.0f * rand () / (RAND_MAX + 1.0f);cloud->points[i].y = 1024.0f * rand () / (RAND_MAX + 1.0f);cloud->points[i].z = 1024.0f * rand () / (RAND_MAX + 1.0f);}// creates kdtree objectpcl::KdTreeFLANN<pcl::PointXYZ> kdtree;// sets our randomly created cloud as the input kdtree.setInputCloud (cloud);//create a “searchPoint” which is assigned random coordinates pcl::PointXYZ searchPoint;searchPoint.x = 1024.0f * rand () / (RAND_MAX + 1.0f);searchPoint.y = 1024.0f * rand () / (RAND_MAX + 1.0f);searchPoint.z = 1024.0f * rand () / (RAND_MAX + 1.0f);// K nearest neighbor searchint K = 1;std::vector<int> pointIdxNKNSearch(K);std::vector<float> pointNKNSquaredDistance(K);std::cout << "K nearest neighbor search at (" << searchPoint.x << " " << searchPoint.y << " " << searchPoint.z<< ") with K=" << K << std::endl;/***********************************************************************************************template<typename PointT> virtual int pcl::KdTree< PointT >::nearestKSearch ( const PointT & p_q, int k, std::vector< int > & k_indices, std::vector< float > & k_sqr_distances ) const [pure virtual] Search for k-nearest neighbors for the given query point. Parameters:[in] the given query point [in] k the number of neighbors to search for [out] the resultant indices of the neighboring points[out] the resultant squared distances to the neighboring pointsReturns:number of neighbors found ********************************************************************************************/if ( kdtree.nearestKSearch (searchPoint, K, pointIdxNKNSearch, pointNKNSquaredDistance) > 0 ){for (size_t i = 0; i < pointIdxNKNSearch.size (); ++i)std::cout << " " << cloud->points[ pointIdxNKNSearch[i] ].x << " " << cloud->points[ pointIdxNKNSearch[i] ].y << " " << cloud->points[ pointIdxNKNSearch[i] ].z << " (squared distance: " << pointNKNSquaredDistance[i] << ")" << std::endl;}//--------------------------------------------------------------------------------------------end = clock(); //結束計時double Times = double(end - begin) / CLOCKS_PER_SEC; //將clock()函數的結果轉化為以秒為單位的量 std::cout<<"time: "<<Times<<"s"<<std::endl;return 0; }

  生成四十萬個隨機點,release版本下測試0.3s左右找到最近點,這比之前自己寫的Kd樹不知快到哪里去了。當然自己寫只是為了更好的理解其中的原理,真要用的時候還得靠別人的輪子...

?

參考:

How to use a KdTree to search

Module kdtree

轉載于:https://www.cnblogs.com/21207-iHome/p/6103354.html

總結

以上是生活随笔為你收集整理的PCL点云库:Kd树的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。