PCL(9)PLC庫和OpenCV庫中的FLANN衝突

清流激湍,孤帆去悠悠發表於2020-10-11

今早在執行k-d tree的demo時,報錯,提示了一大堆未定義識別符號,未找到一些變數的錯誤。
加了很多標頭檔案都未得到解決。最終我選擇了把每個標頭檔案開啟檢查一下。就有了下面的內容。
在這裡插入圖片描述
提示我這個找不到。然後我就開啟了他的宣告,在下面顯示包含在general.h的標頭檔案中,我就
在檔案頭看了一下,發現包含了這個標頭檔案啊:
在這裡插入圖片描述
我把滑鼠點選在general.h上面,提示我這個路徑在pcl的路徑下,沒問題啊,然後我選中它,開啟這個文件,結果轉到了opencv路徑下。。。真狗血,掛著羊頭賣狗肉。
所以我開啟了屬性表,在包含目錄中,將pcl的包含路徑提到了opencv的路徑前面:
在這裡插入圖片描述
然後就解決了這個問題,不得不說狗血的很。

下面是今早用的程式碼:

#include <pcl/point_cloud.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <iostream>
#include <vector>
#include <ctime>
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;
}

在這裡插入圖片描述

相關文章