PCL配置记录
1. Windows10+vs2019+pcl
win10+vs2019+pcl 1.11.1
1.下载与安装
https://github.com/PointCloudLibrary/pcl/releases
)
双击exe安装
注意:
(
)
解压
“pcl-1.11.0-pdb-msvc2019-win64.zip”,将解压得到的文件夹中的内容添加“…\PCL 1.11.0\bin”中。
添加环境变量
2.VS2019中的配置
在VS中新建一个空项目,编译环境改为X64,Release版本。
视图->其他窗口->属性管理器
新建一个项目属性表
双击打开,进入 VC++目录->包含目录,添加:
D:\PCL 1.11.1\include\pcl-1.11
D:\PCL 1.11.1\3rdParty\Boost\include\boost-1_74
D:\PCL 1.11.1\3rdParty\Eigen\eigen3
D:\PCL 1.11.1\3rdParty\Qhull\include
D:\PCL 1.11.1\3rdParty\VTK\include\vtk-8.2
D:\PCL 1.11.1\3rdParty\FLANN\include
C:\Program Files\OpenNI2\Include
VC++目录->库目录,添加:
D:\PCL 1.11.1\lib
D:\PCL 1.11.1\3rdParty\Boost\lib
D:\PCL 1.11.1\3rdParty\FLANN\lib
D:\PCL 1.11.1\3rdParty\Qhull\lib
D:\PCL 1.11.1\3rdParty\VTK\lib
C:\Program Files\OpenNI2\Lib
C/C++—>预处理器—>预处理器定义 添加
BOOST_USE_WINDOWS_H
NOMINMAX
_CRT_SECURE_NO_DEPRECATE
C/C++ ->所有选项->SDL检查 改为否。
链接器—>输入—>附加的依赖项
将PCL 1.11.0\3rdParty\VTK\lib和PCL 1.11.0\lib这两个文件夹下的lib文件的release版本添加到附加依赖项中
为了方便,通过批处理把文件夹中的文件名写入到一个txt中:
//win+r调出“运行”窗口并输出cmd
//(填自己的路径)
cd /d D:\programming\PCL 1.11.0\lib
dir /b *.lib *>0.txt
注意,这个0.txt中会把0.txt和一个pkgconfig文件夹也写进去,复制到附加依赖项之前,应该把这两个删掉,否则会报错
现在该txt中包含了release和debug两种版本的库,如下图,需要将release版本单独分离出来,对于相同功能的库,两个版本是挨着的,可以用程序把他们分别写到两个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()) // 若未到文件结束一直循环{getline(txtfile, temp);//一行一行读取if (index%2==0)//判断除以2的余数,即为奇偶的判断{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(); //关闭文件txtfile.close();txt01.close();txt02.close();return 0;
}
3.测试代码
#include<pcl/visualization/cloud_viewer.h>#include<pcl/io/io.h>
#include<pcl/io/pcd_io.h>//pcd 读写类相关的头文件。
#include<pcl/io/ply_io.h>
#include<pcl/point_types.h> //PCL中支持的点类型头文件。using namespace std;
int split_file();int main(int argc, char** argv)
{pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);char strfilepath[256] = "rabbit.pcd";if (-1 == pcl::io::loadPCDFile(strfilepath, *cloud)) //打开点云文件{std::cout << "error input!" << std::endl;return -1;}std::cout << cloud->points.size() << std::endl;pcl::visualization::CloudViewer viewer("Cloud Viewer"); //创建viewer对象viewer.showCloud(cloud);system("pause");return 0;
}
4.bugFix
C4996 ‘pcl::visualization::PointCloudColorHandler::getColor’: use getColor() without parameters instead (It will be removed in PCL 1.12) PCL_demo D:\PCL 1.11.1\include\pcl-1.11\pcl\visualization\point_cloud_color_handlers.h 109
在代码最前面加上 #pragma warning(disable:4996)
2. Win10+Clion+QT
下载与安装与上一章一致,主要在Clion配置。
环境:win10+clion+opencv+qt 64位
1.配置clion
注意选择64位,因为PCL版本下载的是64位的
2.CmakeList
cmake_minimum_required(VERSION 3.17)
project(project_name)set(CMAKE_CXX_STANDARD 14)add_executable(project_name main.cpp)find_package(PCL 1.11 REQUIRED)
FIND_PACKAGE(PCL REQUIRED COMPONENTS common io visualization )
find_package(OpenCV REQUIRED)include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})target_link_libraries(project_name ${OpenCV_LIBS} ${PCL_LIBRARIES})
3.测试代码
#include <iostream>
#include <pcl/common/common_headers.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/cloud_viewer.h>
#include<opencv2/opencv.hpp>
using namespace cv;int
main (int argc, char** argv)
{Mat img = imread("test.png");imshow("test",img);waitKey(0);pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);char strfilepath[256] = "rabbit.pcd";if (-1 == pcl::io::loadPCDFile(strfilepath, *cloud)) //打开点云文件{std::cout << "error input!" << std::endl;return -1;}std::cout << cloud->points.size() << std::endl;pcl::visualization::CloudViewer viewer("Cloud Viewer"); //创建viewer对象viewer.showCloud(cloud);getchar();return 0;
}
4.QT 配置
QtCreator 与UIC配置
File->settings
配置好后就可以在Tools->external Tools 里找到qtcreator了
也可以右击.ui文件,找到external Tools ,就可以用UIC编译Ui文件了
CmakeList
cmake_minimum_required(VERSION 3.17)
project(project_name)set(CMAKE_CXX_STANDARD 14)set(CMAKE_INCLUDE_CURRENT_DIR ON)
#打开Qt的MOC功能和UI文件处理功能
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
#查找Qt的库
find_package(Qt5Widgets)
add_executable(project_name main.cpp mainwindow.h )find_package(PCL 1.11 REQUIRED)
FIND_PACKAGE(PCL REQUIRED COMPONENTS common io visualization )
find_package(OpenCV REQUIRED)include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})target_link_libraries(project_name ${OpenCV_LIBS} ${PCL_LIBRARIES} Qt5::Widgets)
BugFix
https://blog.csdn.net/jh1513/article/details/52262115
3. QT中VTK的配置
1.VTK重新编译
主要过程见下图链接
https://blog.csdn.net/weixin_43981402/article/details/84845274
下载VTK源码:
https://vtk.org/download/
Cmake编译
设置好两个空目录,一是install 一是prefix
cmake里勾上Qt相关的选项,点击Configure,之后点击Generate,后面就可以在install文件夹里找到sln文件,用vs2019打开,生成解决方案即可。
注意,编译的时候选择release x64
之后前往vtk-prefix文件夹,用里面的文件替换掉${PCL_LIB}\3rdParty\VTK\下的所有文件。
此外,将${PCL_LIB}\3rdParty\VTK\plugins\designer下的QVTKWidgetPlugin.dll文件复制到
${QTLIB}\5.13.2\msvc2017_64\plugins\designer中,就可以在QTdesigner中看到QVTKWidget了。
2.CmakeList
cmake_minimum_required(VERSION 3.17)
project(Mysqlserver_socket)set(CMAKE_CXX_STANDARD 14)set(CMAKE_INCLUDE_CURRENT_DIR ON)
#打开Qt的MOC功能和UI文件处理功能
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
#查找Qt的库
find_package(Qt5Widgets)find_package(VTK)
if(VTK_FOUND)include(${VTK_USE_FILE})
else(VTK_FOUND)message(FATAL_ERROR "cannot bulid without vtk")
endif(VTK_FOUND)set(VTK_LIBS ${VTK_LIBRARIES})find_package(PCL 1.11 REQUIRED)
FIND_PACKAGE(PCL REQUIRED COMPONENTS common io visualization )
find_package(OpenCV REQUIRED)include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})add_executable(Mysqlserver_socket main.cpp mainwindow.h )
target_link_libraries(Mysqlserver_socket ${OpenCV_LIBS} ${PCL_LIBRARIES} ${VTK_LIBS} Qt5::Widgets)
3.测试代码
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDebug>
#include <QFileDialog>
#include<iostream>
#include <vtkRenderWindow.h>MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{ui->setupUi(this);initialVtkWidget();connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(pushButtonTest()));
}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::pushButtonTest() {//只能打开PCD文件QString fileName = QFileDialog::getOpenFileName(this,tr("Open PointCloud"), ".",tr("Open PCD files(*.pcd)"));if (!fileName.isEmpty()){std::string file_name = fileName.toStdString();//sensor_msgs::PointCloud2 cloud2;pcl::PCLPointCloud2 cloud2;//pcl::PointCloud<Eigen::MatrixXf> cloud2;Eigen::Vector4f origin;Eigen::Quaternionf orientation;int pcd_version;int data_type;unsigned int data_idx;int offset = 0;pcl::PCDReader rd;rd.readHeader(file_name, cloud2, origin, orientation, pcd_version, data_type, data_idx);if (data_type == 0){pcl::io::loadPCDFile(fileName.toStdString(), *cloud);}else if (data_type == 2){pcl::PCDReader reader;reader.read<pcl::PointXYZ>(fileName.toStdString(), *cloud);}viewer->updatePointCloud(cloud, "cloud");viewer->resetCamera();ui->qvtkWidget->update();}
}
void MainWindow::initialVtkWidget() {cloud.reset (new pcl::PointCloud<pcl::PointXYZ>);viewer.reset (new pcl::visualization::PCLVisualizer ("viewer", false));viewer->addPointCloud (cloud, "cloud");ui->qvtkWidget->SetRenderWindow(viewer->getRenderWindow ());viewer->setupInteractor (ui->qvtkWidget->GetInteractor (), ui->qvtkWidget->GetRenderWindow ());ui->qvtkWidget->update ();
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <pcl/common/common_headers.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/point_types.h>namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{Q_OBJECTpublic:explicit MainWindow(QWidget *parent = nullptr);~MainWindow();private:Ui::MainWindow *ui;//点云数据存储pcl::PointCloud<pcl::PointXYZ>::Ptr cloud;boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer;//初始化vtk部件void initialVtkWidget();
private slots:void pushButtonTest();
};#endif // MAINWINDOW_H
4.BugFix
1.static_cast: 无法从vtkObjectBase *const转换为“T”
解决方法:
加入
#include <vtkRenderWindow.h>
2.无法链接的外部符号
it MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
//点云数据存储
pcl::PointCloudpcl::PointXYZ::Ptr cloud;
boost::shared_ptrpcl::visualization::PCLVisualizer viewer;
//初始化vtk部件
void initialVtkWidget();
private slots:
void pushButtonTest();
};
#endif // MAINWINDOW_H
### 4.BugFix#### 1.static_cast: 无法从vtkObjectBase *const转换为“T”解决方法:
加入
\#include <vtkRenderWindow.h>#### 2.无法链接的外部符号查看Cmakelist里面find_package的问题