24,860
社区成员




#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;
}
我也是自定义了点类,用到了PCL的SACSegmentation,也和你一样的错误,楼主解决了吗