Win10 系統(tǒng)下VisualStudio2019 配置點云庫 PCL1.11.0的圖文教程
一、下載PCL1.11.0
Github下載地址:https://github.com/PointCloudLibrary/pcl/releases
下載紅框內(nèi)的兩個文件

二、安裝PCL1.11.0
2.1 安裝“PCL-1.11.0-AllInOne-msvc2019-win64.exe”。
(1)選擇第二個,自動添加系統(tǒng)變量

(2)安裝路徑選擇D盤,系統(tǒng)會自動新建PCL 1.11.0文件夾。

2.2 安裝完成之后打開文件夾 D:\PCL 1.11.0\3rdParty\OpenNI2
雙擊OpenNI-Windows-x64-2.2 選擇路徑(D:\PCL 1.11.0\3rdParty\OpenNI2)安裝即可。

2.3 全部安裝完成后,將pcl-1.11.0-pdb-msvc2019-win64.zip解壓后的.pdb文件拷貝到(D:\PCL 1.11.0\bin)中。
2.4 設(shè)置環(huán)境變量:右擊計算機—屬性—高級系統(tǒng)設(shè)置—高級—環(huán)境變量—用戶變量—Path—編輯!

如下圖所示,設(shè)置完成后重啟電腦。

在這里直接給出,防止出現(xiàn)錯誤(依次添加):
%PCL_ROOT%\3rdParty\FLANN\bin
%PCL_ROOT%\3rdParty\VTK\bin
%OPENNI2_REDIST64%
%OPENNI2_LIB64%
%OPENNI2_INCLUDE64%
到此,環(huán)境變量的配置完成。
三、VS2019相關(guān)設(shè)置
3.1 新建空項目

解決方案配置選擇Debug,解決方案平臺選擇x64。

3.2 新建一個C++源文件

3.3 右擊新建的項目—屬性:打開屬性表

3.4 配置屬性—調(diào)試—環(huán)境—添加:
PATH=D:\PCL 1.11.0\\bin;D:\PCL 1.11.0\\3rdParty\FLANN\bin;D:\PCL 1.11.0\\3rdParty\VTK\bin;D:\PCL 1.11.0\\3rdParty\OpenNI2\Tools

3.5 C/C++—語言—符合模式:否

3.6 C/C++—常規(guī)—SDL檢查:否

四、配置PCL1.11.0
為了使用方便,這里使用添加屬性表的形式
4.1 視圖—其他窗口—屬性管理器

4.2 打開屬性管理器之后,選擇Debug|X64—單擊Debug|X64左側(cè)倒三角—右擊選擇 添加型項目屬性表

4.3 項目屬性表命名

4.4 雙擊新添加的屬性表—VC++目錄—包含目錄,添加7個include路徑

具體添加的include路徑如下:
D:\PCL 1.11.0\include\pcl-1.11
D:\PCL 1.11.0\3rdParty\Boost\include\boost-1_73
D:\PCL 1.11.0\3rdParty\Eigen\eigen3
D:\PCL 1.11.0\3rdParty\FLANN\include
D:\PCL 1.11.0\3rdParty\Qhull\include
D:\PCL 1.11.0\3rdParty\VTK\include\vtk-8.2
D:\PCL 1.11.0\3rdParty\OpenNI2\Include
4.5 VC++目錄—包含目錄,添加6個lib路徑

具體添加的lib路徑如下:
D:\PCL 1.11.0\lib
D:\PCL 1.11.0\3rdParty\Boost\lib
D:\PCL 1.11.0\3rdParty\FLANN\lib
D:\PCL 1.11.0\3rdParty\Qhull\lib
D:\PCL 1.11.0\3rdParty\OpenNI2\Lib
D:\PCL 1.11.0\3rdParty\VTK\lib

4.6 C/C++—預處理器—預處理器定義—添加:
BOOST_USE_WINDOWS_H
NOMINMAX
_CRT_SECURE_NO_DEPRECATE

4.7 鏈接器—輸入—附加依賴項——添加PCL和VTK的相關(guān)lib文件。我用的Debug版本。

附加依賴項具體添加內(nèi)容如下:(內(nèi)容略多,放在PCL1.11.0附加依賴項里邊了。文章末尾 附錄中 給出批量獲取附加依賴項的方法)
輸入到屬性表里邊的時候必須一行對應(yīng)一個lib才能成功。
Debug版本
4.8保存屬性表

下一次需要創(chuàng)建新項目的時候,只需進行第三步 VS2019相關(guān)設(shè)置 的操作,然后打開屬性管理器,添加現(xiàn)有屬性表,找到之前保存的屬性表添加進去即可。


五、測試代碼
#include <iostream>
#include <vector>
#include <ctime>
#include <pcl/point_cloud.h>
#include <pcl/octree/octree.h>
#include <boost/thread/thread.hpp>
#include <pcl/visualization/pcl_visualizer.h>
using namespace std;
int
main(int argc, char** argv)
{
srand((unsigned int)time(NULL));
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// 創(chuàng)建點云數(shù)據(jù)
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::octree::OctreePointCloudSearch<pcl::PointXYZ> octree(0.1);
octree.setInputCloud(cloud);
octree.addPointsFromInputCloud();
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);
//半徑內(nèi)近鄰搜索
vector<int>pointIdxRadiusSearch;
vector<float>pointRadiusSquaredDistance;
float radius = 256.0f * rand() / (RAND_MAX + 1.0f);
cout << "Neighbors within radius search at (" << searchPoint.x
<< " " << searchPoint.y
<< " " << searchPoint.z
<< ") with radius=" << radius << endl;
if (octree.radiusSearch(searchPoint, radius, pointIdxRadiusSearch, pointRadiusSquaredDistance) > 0)
{
for (size_t i = 0; i < pointIdxRadiusSearch.size(); ++i)
cout << " " << cloud->points[pointIdxRadiusSearch[i]].x
<< " " << cloud->points[pointIdxRadiusSearch[i]].y
<< " " << cloud->points[pointIdxRadiusSearch[i]].z
<< " (squared distance: " << pointRadiusSquaredDistance[i] << ")" << endl;
}
// 初始化點云可視化對象
boost::shared_ptr<pcl::visualization::PCLVisualizer>viewer(new pcl::visualization::PCLVisualizer("顯示點云"));
viewer->setBackgroundColor(0, 0, 0); //設(shè)置背景顏色為黑色
// 對點云著色可視化 (red).
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>target_color(cloud, 255, 0, 0);
viewer->addPointCloud<pcl::PointXYZ>(cloud, target_color, "target cloud");
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "target cloud");
// 等待直到可視化窗口關(guān)閉
while (!viewer->wasStopped())
{
viewer->spinOnce(100);
boost::this_thread::sleep(boost::posix_time::microseconds(1000));
}
return (0);
}
輸出下圖(數(shù)字可能不同),則表示安裝成功!

六、附錄—獲取自己的鏈接庫列表
win+r調(diào)出“運行”窗口并輸出cmd
輸入:cd /d D:\PCL 1.11.0\3rdParty\VTK\lib 回車 (填自己的路徑)
輸入:dir /b *.lib *>0.txt 回車

這時打開你對應(yīng)路勁的目錄,多了一個0.txt文件,里面存了你這個文件夾里所有鏈接庫名字。
由于每一個Debug版本和Release版本的鏈接庫是挨在一起的。寫一個讀取文檔并對其分別保存就行了。
具體代碼如下:(主要功能是讀取一個txt文件,將其中奇數(shù)行和偶數(shù)行單獨輸出到新的txt文檔。)
#include <iostream>
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream txtfile;//打開讀取的文件
ofstream txt01;//保存的文件
ofstream txt02;//保存的文件
string temp;
int index = 0;//用于判斷奇偶
txtfile.open("0.txt", ios::in);
while (!txtfile.eof()) // 若未到文件結(jié)束一直循環(huán)
{
getline(txtfile, temp);//一行一行讀取
if (index%2==0)//判斷除以2的余數(shù),即為奇偶的判斷
{
txt01.open("1.txt", ios::app);
txt01 << temp;
txt01 << endl;
txt01.close();
}
else
{
txt02.open("2.txt", ios::app);
txt02 << temp;
txt02 << endl;
txt02.close();
}
index++;
}
txtfile.close(); //關(guān)閉文件
txtfile.close();
txt01.close();
txt02.close();
return 0;
}
到此這篇關(guān)于Win10 系統(tǒng)下VisualStudio2019 配置點云庫 PCL1.11.0的圖文教程的文章就介紹到這了,更多相關(guān)VisualStudio2019 配置點云庫 PCL1.11.0內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
WPF自定義TreeView控件樣式實現(xiàn)QQ聯(lián)系人列表效果
TreeView控件在項目中使用比較頻繁,下面這篇文章主要給大家介紹了關(guān)于WPF自定義TreeView控件樣式實現(xiàn)QQ聯(lián)系人列表效果的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面來一起看看吧。2018-04-04
C#如何優(yōu)雅的對WinForm窗體應(yīng)用程序進行權(quán)限控制
經(jīng)常會出現(xiàn)winfrom頁面需要加載權(quán)限樹,下面這篇文章主要給大家介紹了關(guān)于C#如何優(yōu)雅的對WinForm窗體應(yīng)用程序進行權(quán)限控制的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-11-11

