win10+vs2019+pcl 1.11.1
https://github.com/PointCloudLibrary/pcl/releases
)
注意:
“pcl-1.11.0-pdb-msvc2019-win64.zip”,将解压得到的文件夹中的内容添加“…\PCL 1.11.0\bin”中。
在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
#include
#include
#include
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;
}
#include
#include
#include//pcd 读写类相关的头文件。
#include
#include //PCL中支持的点类型头文件。
using namespace std;
int split_file();
int main(int argc, char** argv)
{
pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
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;
}
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)
下载与安装与上一章一致,主要在Clion配置。
环境:win10+clion+opencv+qt 64位
注意选择64位,因为PCL版本下载的是64位的
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})
#include
#include
#include
#include
#include
#include
using namespace cv;
int
main (int argc, char** argv)
{
Mat img = imread("test.png");
imshow("test",img);
waitKey(0);
pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
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;
}
File->settings
配置好后就可以在Tools->external Tools 里找到qtcreator了
也可以右击.ui文件,找到external Tools ,就可以用UIC编译Ui文件了
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)
https://blog.csdn.net/jh1513/article/details/52262115
主要过程见下图链接
https://blog.csdn.net/weixin_43981402/article/details/84845274
https://vtk.org/download/
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了。
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)
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include
#include
#include
#include
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 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(fileName.toStdString(), *cloud);
}
viewer->updatePointCloud(cloud, "cloud");
viewer->resetCamera();
ui->qvtkWidget->update();
}
}
void MainWindow::initialVtkWidget() {
cloud.reset (new pcl::PointCloud);
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
#include
#include
#include
#include
#include
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
//点云数据存储
pcl::PointCloud::Ptr cloud;
boost::shared_ptr viewer;
//初始化vtk部件
void initialVtkWidget();
private slots:
void pushButtonTest();
};
#endif // MAINWINDOW_H
解决方法:
加入
#include
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
#### 2.无法链接的外部符号
查看Cmakelist里面find_package的问题