• 大小: 73.22MB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2022-09-01
  • 语言: 其他
  • 标签: VS2017  PCL  点云  

资源简介

本例子是自己捣鼓了两天半才搞定的资源,最后使用Cmake的编译,才最终成功。代码上可能有些是绝对路径,下载的朋友只需要将路径改为自己安装PCL的路径即可,另外,建议初学者在安装PCL的时候不做路径的修改,直接安装到默认的文件夹即可,本人就是因为修改路径,导致多次出错。

资源截图

代码片段和文件信息

#include 
#include 

#include 
#include 
#include 

int main(int argc char** argv)
{
srand(time(NULL)); //用系统时间初始化随机种子

pcl::PointCloud::Ptr cloud(new pcl::PointCloud);

// Generate pointcloud data 随机点云生成
cloud->width = 1000; //点云数量
cloud->height = 1; //点云为无序点云
cloud->points.resize(cloud->width * cloud->height);

for (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);
}

pcl::KdTreeFLANN kdtree; //创建kd-tree

kdtree.setInputCloud(cloud); //设置搜索空间

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 search k 近邻搜索
int K = 10;
std::vector pointIdxNKNSearch(K);
std::vector pointNKNSquaredDistance(K);
std::cout << “K nearest neighbor search at (“ << searchPoint.x
<< “ “ << searchPoint.y
<< “ “ << searchPoint.z
<< “) with K=“ << K << std::endl;

if (kdtree.nearestKSearch(searchPoint K pointIdxNKNSearch pointNKNSquaredDistance) > 0) //执行k近邻搜索
{
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;
}

// Neighbors within radius search 半径r内近邻搜索方式

std::vector pointIdxRadiusSearch; //存储近邻索引
std::vector pointRadiusSquaredDistance; //存储近邻对应的距离平方
float radius = 256.0f * rand() / (RAND_MAX + 1.0f);

std::cout << “Neighbors within radius search at (“ << searchPoint.x
<< “ “ << searchPoint.y
<< “ “ << searchPoint.z
<< “) with radius=“ << radius << std::endl;


if (kdtree.radiusSearch(searchPoint radius pointIdxRadiusSearch pointRadiusSquaredDistance) > 0)
{
for (size_t i = 0; i < pointIdxRadiusSearch.size(); ++i)
std::cout << “    “ << cloud->points[pointIdxRadiusSearch[i]].x
<< “ “ << cloud->points[pointIdxRadiusSearch[i]].y
<< “ “ << cloud->points[pointIdxRadiusSearch[i]].z
<< “ (squared distance: “ << pointRadiusSquaredDistance[i] << “)“ << std::endl;
}
system(“pause“);
return 0;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-12-02 17:43  Project1\
     目录           0  2019-12-02 17:43  Project1\.vs\
     目录           0  2019-12-02 17:43  Project1\.vs\Project1\
     目录           0  2019-12-02 17:43  Project1\.vs\Project1\v15\
     文件       24576  2019-12-02 16:36  Project1\.vs\Project1\v15\.suo
     文件     5464064  2019-12-02 16:36  Project1\.vs\Project1\v15\Browse.VC.db
     目录           0  2019-12-02 17:43  Project1\.vs\Project1\v15\ipch\
     目录           0  2019-12-02 17:43  Project1\.vs\Project1\v15\ipch\AutoPCH\
     目录           0  2019-12-02 17:43  Project1\.vs\Project1\v15\ipch\AutoPCH\8e3285934654fb92\
     文件    33357824  2019-12-01 21:21  Project1\.vs\Project1\v15\ipch\AutoPCH\8e3285934654fb92\KD_TREE.ipch
     目录           0  2019-12-02 17:43  Project1\.vs\Project1\v15\ipch\AutoPCH\e096050e3b828a1\
     文件    33947648  2019-12-02 16:36  Project1\.vs\Project1\v15\ipch\AutoPCH\e096050e3b828a1\KD_TREE.ipch
     文件         303  2019-12-02 16:35  Project1\CMakeLists
     文件         303  2019-12-02 13:30  Project1\CMakeLists.txt
     目录           0  2019-12-02 17:43  Project1\cmake_bin\
     目录           0  2019-12-02 17:43  Project1\cmake_bin\.vs\
     目录           0  2019-12-02 17:43  Project1\cmake_bin\.vs\Kd_tree\
     目录           0  2019-12-02 17:43  Project1\cmake_bin\.vs\Kd_tree\v15\
     文件       34304  2019-12-02 16:39  Project1\cmake_bin\.vs\Kd_tree\v15\.suo
     文件    72372224  2019-12-02 16:34  Project1\cmake_bin\.vs\Kd_tree\v15\Browse.VC.db
     文件          58  2019-12-02 16:37  Project1\cmake_bin\.vs\Kd_tree\v15\Browse.VC.opendb
     目录           0  2019-12-02 17:43  Project1\cmake_bin\.vs\Kd_tree\v15\ipch\
     目录           0  2019-12-02 17:43  Project1\cmake_bin\.vs\Kd_tree\v15\ipch\AutoPCH\
     目录           0  2019-12-02 17:43  Project1\cmake_bin\.vs\Kd_tree\v15\ipch\AutoPCH\7f42d19b7186464c\
     文件   186646528  2019-12-02 16:38  Project1\cmake_bin\.vs\Kd_tree\v15\ipch\AutoPCH\7f42d19b7186464c\KD_TREE.ipch
     文件      790528  2019-12-02 13:38  Project1\cmake_bin\.vs\Kd_tree\v15\Solution.VC.db
     文件       32768  2019-12-02 16:37  Project1\cmake_bin\.vs\Kd_tree\v15\Solution.VC.db-shm
     文件       12392  2019-12-02 16:37  Project1\cmake_bin\.vs\Kd_tree\v15\Solution.VC.db-wal
     文件       60904  2019-12-02 13:32  Project1\cmake_bin\ALL_BUILD.vcxproj
     文件         291  2019-12-02 13:32  Project1\cmake_bin\ALL_BUILD.vcxproj.filters
     文件         165  2019-12-02 13:34  Project1\cmake_bin\ALL_BUILD.vcxproj.user
............此处省略108个文件信息

评论

共有 条评论