PCL在win10環境Visual Studio2015中的配置
阿新 • • 發佈:2019-01-25
本文介紹在windows環境下配置PCL1.80的開發環境。
電腦配置如下:
1.windows 10 64位作業系統
2.下載對應Visual Studio 2015 64 位PCL1.8和對應的PDB檔案
1.點選安裝對應的PCL檔案,安裝過程中勾選配置系統環境變數
把PDB檔案解壓縮,把裡面所有的.pdb檔案拷貝到PCL安裝bin目錄下
2.安裝完成後,得到環境變數下的如下:
以上幾個是自己安裝過程中自動新增的,下面需要自己手動新增幾個環境變數
3.接著開啟visual studio 2015,新建專案檔案,然後配置對應的屬性檔案,點選DEBUG 64,新增新屬性表文件。
把對應的包和庫目錄檔案一併新增進來
4.接著新增聯結器-輸入,把對應的lib檔案新增
其中的PCL安裝目錄下的lib資料夾,以及下面幾個資料夾下的lib資料夾下的檔案都新增
我的屬性表文件下載如下:
http://download.csdn.net/detail/oliverkingli/9828188
4.
接著使用以下程式碼進行測試:
我的是使用opencv配置環境下學習高翔博士的slam#include <pcl/visualization/cloud_viewer.h> #include <iostream> #include <pcl/io/io.h> #include <pcl/io/pcd_io.h> int user_data; void viewerOneOff(pcl::visualization::PCLVisualizer& viewer) { viewer.setBackgroundColor(1.0, 0.5, 1.0); pcl::PointXYZ o; o.x = 1.0; o.y = 0; o.z = 0; viewer.addSphere(o, 0.25, "sphere", 0); std::cout << "i only run once" << std::endl; } void viewerPsycho(pcl::visualization::PCLVisualizer& viewer) { static unsigned count = 0; std::stringstream ss; ss << "Once per viewer loop: " << count++; viewer.removeShape("text", 0); viewer.addText(ss.str(), 200, 300, "text", 0); //FIXME: possible race condition here: user_data++; } int main() { pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGBA>); pcl::io::loadPCDFile("my_point_cloud.pcd", *cloud); pcl::visualization::CloudViewer viewer("Cloud Viewer"); //blocks until the cloud is actually rendered viewer.showCloud(cloud); //use the following functions to get access to the underlying more advanced/powerful //PCLVisualizer //This will only get called once viewer.runOnVisualizationThreadOnce(viewerOneOff); //This will get called once per visualization iteration viewer.runOnVisualizationThread(viewerPsycho); while (!viewer.wasStopped()) { //you can also do cool processing here //FIXME: Note that this is running in a separate thread from viewerPsycho //and you should guard against race conditions yourself... user_data++; } return 0; }
得到的點雲圖如下:// RGB_D_slam_test1.2.cpp : 定義控制檯應用程式的入口點。 // #include "stdafx.h" // c++標準庫 #include <iostream> #include <string> using namespace std; // Opencv 庫 #include <opencv2\core\core.hpp> #include <opencv2\highgui\highgui.hpp> // PCL 庫 #include <pcl\io\pcd_io.h> #include <pcl\point_types.h> // 定義點雲型別 typedef pcl::PointXYZRGBA PointT; typedef pcl::PointCloud<PointT> PointCloud; // 相機引數 const double camera_factor = 1000; const double camera_cx = 325.5; const double camera_cy = 253.5; const double camera_fx = 518.0; const double camera_fy = 519.0; int _tmain(int argc, _TCHAR* argv[]) { // 影象矩陣 cv::Mat rgb, depth; // rgb 是8UC3的彩色影象 rgb = cv::imread("data\\rgb.png"); // depth 是16UC1的單通道影象,flags設定-1,表示讀取原始資料不做任何的修改 depth = cv::imread("data\\depth.png", -1); // 點雲變數;使用智慧指標,建立一個空點雲 PointCloud::Ptr cloud(new PointCloud); // 遍歷深度圖 for (int m = 0; m < depth.rows; ++m) { for (int n = 0; n < depth.cols; ++n) { // 獲取深度圖中(m,n)處的值 ushort d = depth.ptr<ushort>(m)[n]; if (d == 0) continue; PointT p; // 計算這個點的空間座標 p.z = double(d) / camera_factor; p.x = (n - camera_cx) * p.z / camera_fx; p.y = (m - camera_cy) * p.z / camera_fy; // 從rgb影象中獲取它的顏色 // rgb是三通道的RGB格式圖,所以俺下面的順序獲取顏色 p.b = rgb.ptr<uchar>(m)[n * 3]; p.g = rgb.ptr<uchar>(m)[n * 3 + 1]; p.r = rgb.ptr<uchar>(m)[n * 3 + 2]; // 把p加入到點雲中 cloud->points.push_back(p); } } // 設定並儲存點雲 cloud->height = 1; cloud->width = cloud->points.size(); cout << "point cloud size = " << cloud->points.size() << endl; cloud->is_dense = false; pcl::io::savePCDFile("data\\pointcloud.pcd", *cloud); // 清楚資料並退出 cloud->points.clear(); cout << "point cloud saved." << endl; return 0; }