為了方便資料處理,我自定義了點云的點型別,然后使用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;
}
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
#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).
uj5u.com熱心網友回復:
好像不能用自己定義的點云型別使用kdtree轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/22498.html
標籤:工具平臺和程序庫
上一篇:如何用C語言實作自定義彈窗與選項
