PCL中自定义了Point类型,使用KDtree的时候出现了问题

qq_35539074 2019-12-17 04:25:34
为了方便数据处理,我自定义了点云的点类型,然后使用kdtreeFlann进行近邻搜索,但是出现了以下问题



完整的代码如下,望大佬指点,我还是一个C++新手

#include<pcl/io/io.h>
#include<pcl/io/pcd_io.h>//pcd 读写类相关的头文件。
#include<pcl/point_types.h> //PCL中支持的点类型头文件。
#include<pcl/point_cloud.h>
#include <pcl/kdtree/kdtree_flann.h>
#include<pcl/filters/passthrough.h>
#include<pcl/filters/impl/passthrough.hpp>

using namespace std;

struct PointWithLabel {
PCL_ADD_POINT4D;
int label;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
}EIGEN_ALIGN16;
POINT_CLOUD_REGISTER_POINT_STRUCT(PointWithLabel,
(float, x, x)
(float, y, y)
(float, z, z)
(int, label, label)
)
int main() {

//pcl::PointXYZ ins;
pcl::PointCloud<PointWithLabel>::Ptr cloud(new pcl::PointCloud<PointWithLabel>);
//pcl::PointCloud<PointWithLabel> cloud;
char strfilepath[256] = "label.pcd";
if (-1 == pcl::io::loadPCDFile(strfilepath, *cloud)) //打开点云文件
{
cout << "error input!" << endl;
return -1;
}
for (int i = 0; i < 10; i++) {
cout << " " << cloud->points[i].x
<< " " << cloud->points[i].y
<< " " << cloud->points[i].z
<< " " << cloud->points[i].label
<< endl;
}
pcl::KdTreeFLANN < PointWithLabel > kdtree; //创建KDtree

kdtree.setInputCloud(cloud);

PointWithLabel searchPoint; //创建目标点,(搜索该点的近邻)
searchPoint.x = cloud->points[100].x;
searchPoint.y = cloud->points[100].y;
searchPoint.z = cloud->points[100].z;
searchPoint.label = cloud->points[100].label;

//查询近邻点的个数
int k = 10; //近邻点的个数
std::vector<int> pointIdxNKNSearch(k); //存储近邻点集的索引
std::vector<float>pointNKNSquareDistance(k); //近邻点集的距离
if (kdtree.nearestKSearch(searchPoint, k, pointIdxNKNSearch, pointNKNSquareDistance)>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
//<< " " << cloud->points[pointIdxNKNSearch[i]].label
<< " (squared distance: " << pointNKNSquareDistance[i] << ")" << std::endl;
}
system("pause");
return 0;


}

...全文
1929 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
肖蜗牛 2021-08-12
  • 打赏
  • 举报
回复

我也是自定义了点类,用到了PCL的SACSegmentation,也和你一样的错误,楼主解决了吗

weixin_53110214 2021-05-06
  • 打赏
  • 举报
回复
我也遇到这问题了,请问解决了 吗
  • 打赏
  • 举报
回复
好像不能用自己定义的点云类型使用kdtree
CodingGorilla.li 2020-04-21
  • 打赏
  • 举报
回复 3
#define PCL_NO_PRECOMPILE
在文件头加上这个宏
If your code is part of the library, which gets used by others, it might also make sense to try to use explicit instantiations for your MyPointType types, for any classes that you expose (from PCL our outside PCL).
qq_35539074 2019-12-17
  • 打赏
  • 举报
回复

24,860

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧