PCL(9)PLC库和OpenCV库中的FLANN冲突

今早在运行k-d tree的demo时,报错,提示了一大堆未定义标识符,未找到一些变量的错误。
加了很多头文件都未得到解决。最终我选择了把每个头文件打开检查一下。就有了下面的内容。
PCL(9)PLC库和OpenCV库中的FLANN冲突_第1张图片
提示我这个找不到。然后我就打开了他的声明,在下面显示包含在general.h的头文件中,我就
在文件头看了一下,发现包含了这个头文件啊:
PCL(9)PLC库和OpenCV库中的FLANN冲突_第2张图片
我把鼠标点击在general.h上面,提示我这个路径在pcl的路径下,没问题啊,然后我选中它,打开这个文档,结果转到了opencv路径下。。。真狗血,挂着羊头卖狗肉。
所以我打开了属性表,在包含目录中,将pcl的包含路径提到了opencv的路径前面:
PCL(9)PLC库和OpenCV库中的FLANN冲突_第3张图片
然后就解决了这个问题,不得不说狗血的很。

下面是今早用的代码:

#include 
#include 
#include 
#include 
#include 
int main(int argc, char** argv)
{
     
	srand(time(NULL));
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
	//点云生成
	cloud->width = 1000;//点云数量
	cloud->height = 1;  //无序点云
	cloud->points.resize(cloud->width * cloud->height);
	for (size_t i = 0; i < cloud->points.size(); ++i)
	{
     
		cloud->points[i].x = 1024.0f * rand() / (RAND_MAX + 1.0f);
		cloud->points[i].y = 1024.0f * rand() / (RAND_MAX + 1.0f);
		cloud->points[i].z = 1024.0f * rand() / (RAND_MAX + 1.0f);
	}

	pcl::KdTreeFLANN<pcl::PointXYZ>kdtree;//循环创建kd-tree对象
	kdtree.setInputCloud(cloud);          //设置搜索空间即输入点云
	pcl::PointXYZ searchPoint;            //定义查询点,并随机赋值
	searchPoint.x = 1024.0f * rand() / (RAND_MAX + 1.0f);
	searchPoint.y = 1024.0f * rand() / (RAND_MAX + 1.0f);
	searchPoint.z = 1024.0f * rand() / (RAND_MAX + 1.0f);

	// k近邻搜索
	int K = 10;
	std::vector<int>pointIdxNKNSearch(K);        //存储查询点近邻索引
	std::vector<float>pointNKNSquaredDistance(K);//存储近邻点对应平方距离
	// 打印查询点邻域内的K个邻近点
	std::cout << "K nearest neighbor search at (" << searchPoint.x
		<< " " << searchPoint.y
		<< " " << searchPoint.z
		<< ") with K=" << K << std::endl;
	if (kdtree.nearestKSearch(searchPoint, K, pointIdxNKNSearch, pointNKNSquaredDistance) > 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
			<< " (squared distance: " << pointNKNSquaredDistance[i] << ")" << std::endl;
	}

	// 在半径r内搜索近邻
	std::vector<int> pointIdxRadiusSearch;        //存储查询点近邻索引
	std::vector<float> pointRadiusSquaredDistance;//存储近邻点对应平方距离
	float radius = 256.0f * rand() / (RAND_MAX + 1.0f);

	// 打印查询点邻域r范围内的邻近点
	std::cout << "Neighbors within radius search at (" << searchPoint.x
		<< " " << searchPoint.y
		<< " " << searchPoint.z
		<< ") with radius=" << radius << std::endl;
	if (kdtree.radiusSearch(searchPoint, radius, pointIdxRadiusSearch, pointRadiusSquaredDistance) > 0)
	{
     
		for (size_t i = 0; i < pointIdxRadiusSearch.size(); ++i)
			std::cout << "    " << cloud->points[pointIdxRadiusSearch[i]].x
			<< " " << cloud->points[pointIdxRadiusSearch[i]].y
			<< " " << cloud->points[pointIdxRadiusSearch[i]].z
			<< " (squared distance: " << pointRadiusSquaredDistance[i] << ")" << std::endl;
	}

	return 0;
}

PCL(9)PLC库和OpenCV库中的FLANN冲突_第4张图片

你可能感兴趣的:(pcl)