博客
关于我
基于PCL利用kdtree计算点云点距均值
阅读量:301 次
发布时间:2019-03-01

本文共 2424 字,大约阅读时间需要 8 分钟。

C++程序运行闪退解决方法:

1.主函数中return 0;前加getchar();需要头文件<iostream>

2.主函数return 0;前加system("pause");

其中代码中在main()函数中添加return true前加了getchar();

注意:代码中提示无法找到源文件pch.h,可以将其注释掉,对代码运行不产生影响!

代码如下:

// PointCloudsDis.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。////#include "pch.h"#include 
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;double computerCloudResolution(const pcl::PointCloud
::ConstPtr cloud) { double res = 0.0; int n_points = 0; int nres; std::vector
indices(2); std::vector
sqr_distances(2); pcl::search::KdTree
tree; tree.setInputCloud(cloud); for (size_t i = 0; i < cloud->size(); ++i) { if (!std::isfinite((*cloud)[i].x)) { continue; } nres = tree.nearestKSearch(i, 2, indices, sqr_distances); if (nres == 2) { res += sqrt(sqr_distances[1]); ++n_points; } } if (n_points != 0) { res /= n_points; } return res; }int main(){ ifstream data; data.open("knee_piece.TXT", ios::in); int rows = -1; char buf[200]; while (!data.eof()) { data.getline(buf, sizeof(buf)); rows++; } data.clear(); data.seekg(0, ios::beg); //pcl::PointCloud
cloud; pcl::PointCloud
::Ptr cloud(new pcl::PointCloud
); cloud->width = rows; cloud->height = 1; cloud->is_dense = false; cloud->resize(cloud->width*cloud->height); for (int i = 0; i < rows; i++) { double num[3]; data >> num[0]; data >> num[1]; data >> num[2]; cloud->points[i].x = num[0]; cloud->points[i].y = num[1]; cloud->points[i].z = num[2]; } double res = computerCloudResolution(cloud); cout << "distance=" << res << endl << "rows=" << rows; getchar(); //防止窗口闪退 return true;}

温馨提示:

积分下载名字叫“基于PCL的点云平均间距计算”,其实真没什么意思,就是以下这段代码,其实和上文中的一样的,况且代码中仅有计算点云间距的代码!下载链接:

不要冤枉浪费积分!

#include 
float means_re(pcl::PointCloud
::Ptr cloud){ float res = 0.0; int n_points = 0; int nres; std::vector
indices(2); std::vector
sqr_distances(2); pcl::KdTreeFLANN
tree; tree.setInputCloud(cloud); for (size_t i = 0; i < cloud->size(); ++i) { if (!pcl_isfinite(cloud->points[i].x)) { continue; } //Considering the second neighbor since the first is the point itself. nres = tree.nearestKSearch(i, 2, indices, sqr_distances); if (nres == 2) { res += sqrt(sqr_distances[1]); ++n_points; } } if (n_points != 0) { res /= n_points; } //std::cout <<"平均距离:"<
<

 参考博文:

1、

2、

 

转载地址:http://ogdo.baihongyu.com/

你可能感兴趣的文章
MySql 查询以逗号分隔的字符串的方法(正则)
查看>>
MySQL 查询优化:提速查询效率的13大秘籍(避免使用SELECT 、分页查询的优化、合理使用连接、子查询的优化)(上)
查看>>
mysql 查询数据库所有表的字段信息
查看>>
【Java基础】什么是面向对象?
查看>>
mysql 查询,正数降序排序,负数升序排序
查看>>
MySQL 树形结构 根据指定节点 获取其下属的所有子节点(包含路径上的枝干节点和叶子节点)...
查看>>
mysql 死锁 Deadlock found when trying to get lock; try restarting transaction
查看>>
mysql 死锁(先delete 后insert)日志分析
查看>>
MySQL 死锁了,怎么办?
查看>>
MySQL 深度分页性能急剧下降,该如何优化?
查看>>
MySQL 深度分页性能急剧下降,该如何优化?
查看>>
MySQL 添加列,修改列,删除列
查看>>
mysql 添加索引
查看>>
MySQL 添加索引,删除索引及其用法
查看>>
mysql 状态检查,备份,修复
查看>>
MySQL 用 limit 为什么会影响性能?
查看>>
MySQL 用 limit 为什么会影响性能?有什么优化方案?
查看>>
MySQL 用户权限管理:授权、撤销、密码更新和用户删除(图文解析)
查看>>
mysql 用户管理和权限设置
查看>>
MySQL 的 varchar 水真的太深了!
查看>>