资源简介
基于PCL写的一个删除点云数据中的重复点的程序,也可以稍作修改删除数组中的重复点。目前测试一个四千万个点的点云数据,其中包含有一千万个重复点,运行时间为50s。
文件中是源码,其中包含CMakeLists.txt,可通过配置pcl后直接使用,也可直接复制代码使用

代码片段和文件信息
#include
#include
#include
#include
#include
int numofPoints(const char* fname) {
int n = 0;
int c = 0;
FILE *fp;
fp = fopen(fname “r“);
do {
c = fgetc(fp);
if (c == ‘\n‘) {
++n;
}
} while (c != EOF);
fclose(fp);
return n;
}
pcl::PointCloud repeat_point_remove(pcl::PointCloud::Ptr cloud_ptr)
{
srand(time(NULL));
time_t begin end;
begin = clock();//开始计时
pcl::KdTreeFLANN kdtree;
kdtree.setInputCloud(cloud_ptr);
std::vector pointIdxRadiusSearch;//进行r邻域点搜索
std::vector pointRadiusSquaredDistance;
std::vector total_index;
float radius = 0.000001;//若两点之间的距离为0.000001则认为是重合点
pcl::PointCloud::Ptr repeat_cloud_ptr(new pcl::PointCloud);
for (int i = 0; i < cloud_ptr->size(); ++i)//对A中的每个点与B中点进行比较
{
if (kdtree.radiusSearch(cloud_ptr->points[i] radius pointIdxRadiusSearch pointRadiusSquaredDistance) > 0)
{
if (pointIdxRadiusSearch.size() != 1)//若某一点在0.000001领域内不止其本身一个点,则认为其有重复点
{
for (size_t j = 1; j < pointIdxRadiusSearch.size(); j++)
{
total_index.push_back(pointIdxRadiusSearch[j]);//将重复点的索引记录下来,由于后续以此重复点为查询点搜索时,此时这一点也会被定义为重复点,但pointIdxRadiusSearch中都是升序排列的,故从pointIdxRadiusSearch中的第二个点的索引开始记录,这样可以保证仅仅删除重复的点,即会留一个
}
}
}
if (i % 1000000 == 0)
{
std::cout << i << std::endl;//进度记录
}
}
sort(total_index.begin() total_index.end());//将索引进行排序
total_index.erase(unique(total_index.begin() total_index.end()) total_index.end());//将索引中的重复索引去除
pcl::PointIndices::Ptr outliners(new pcl::PointIndices());//通过pcl中的extract类根据索引删除点,则剩下的就不是重复点了
outliners->indices.resize(total_index.size());
for (size_t i = 0; i < total_index.size(); i++)
{
outliners->indices[i] = total_index[i];
}
std::cout << “total_index_getting has been done“ << std::endl;
pcl::ExtractIndices extract;
extract.setInputCloud(cloud_ptr);
extract.setIndices(outliners);
extract.setNegative(true);
extract.filter(*cloud_ptr);
std::cout << “the num of repeat point is:“ << total_index.size() << std::endl;
std::cout << “the num of repeat point is:“ << cloud_ptr->points.size() << std::endl;
end = clock();//结束计时
double Times = double(end - begin) / CLOCKS_PER_SEC;
std::cout << “time:“ << Times << “s“ << std::endl;
return *cloud_ptr;
}
int main()
{
int num_of_repeat_point = 0;
int n = 0; //n用来计文件中点个数
FILE *fp_1;
fp_1 = fopen(“import_test_without_normal.txt“ “r“);//输入要读取的文件名称,下同
n = numofPoints(“import_test_without_normal.txt“);//使用numofPoints函数计算文件中点个数
std::cout << “there are “ << n << “ points in the file...“ << std::endl;
pcl::PointCloud::Ptr cloud_ptr(new pcl::PointCloud);
double x y z;
for (unsigned int i = 0; i < n; ++i)//将所读取的点云和与其对应的ID存储在gloalelements里,同时逐步获得最大包围盒
{
fscanf(fp_1 “%lf %lf %lf
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 566 2019-08-06 21:06 source\CMakeLists.txt
文件 3734 2019-08-06 21:30 source\main.cpp
目录 0 2019-08-06 21:30 source\
- 上一篇:log4j.properties
- 下一篇:疫情地图.zip
相关资源
- 汉印A300 CPCL协议 android 热敏打印app(
- 超级场景清理器(SPCleaner)v1.0免费版
- httpclient4.3工具类
- SfM稀疏三维点云重建--完整工程文件
- 全面的点云库PCL学习教程
- CPCL查看器.rar
- Linux ntpclient代码
- 点云库PCL学习教程 完整版
- 中英文PCL5语言参考手册_11086676.zip
- stm32f4+w5500+tcpclient/server源码
- PC-lint 9 + 中文手册
- 建筑物的地面扫描点云数据
- FTPclinet客户端
- PCL点云库SACSegmentation用法demo
- 小兔子pcd点云数据pcl官方案例1)
- fandisk点云数据,asc文件数据,三维模
- PCL5编程指南中文版
- 点云试验数据
- 点云数据读取 使用osg 附带点云数据
- osg显示点云
- 利用PCL,OpenCV求取点云的体积
- Cyclone快速入门中文版
- 知名的斯坦福兔子的三维点云数据,
- pcl5语言详细介绍
- httpclient-4.5.3 api 中文版
- stm32 lwip DNS DHCP ucosIII TCP Client 原创程
- HttpClient异步请求
- pcl点云模型
- HanV1.0.rar
- 基于点云数据的三维重建
评论
共有 条评论