Qt6.1.0中配置pcl1.11.1

一、准备工作

1、安装Qt6.1.0

使用online在线安装,可以从国内镜像地址下载,也可百度网盘提取码:pefj

2、安装PCL1.11.1

可以从国内镜像地址下载,或百度网盘 提取码:eonx,安装完成后将zip文件解压,内容放入bin

3、整理PCL库

pcl1.11.1安装后的配置(vs2019)

二、为Qt配置pcl

主要做三件事,即添加include、lib、附加依赖项,都在.pro文件中进行
首先,打开Qt Creater,创建个简单的控制台应用(方便测试配置是否成功)
在这里插入图片描述

1、配置include

在.pro文件中加入如下内容

INCLUDEPATH +=整理好的pcl的include目录
eg.
INCLUDEPATH +=G:\c++_code\lib_3d\pcl\inc

2、配置lib

在.pro文件中加入如下内容,将“ ”中的目录换成自己的pcl lib目录

win32:CONFIG(release, debug|release): LIBS +=-L"G:\c++_code\lib_3d\pcl\lib"
else:win32:CONFIG(debug, debug|release): LIBS +=-L"G:\c++_code\lib_3d\pcl\lib"

3、添加附加依赖项

pcl1.11.1安装后的配置(vs2019)中的附加依赖项添加到.pro文件中

1、利用界面功能创建一个添加lib的模板

在这里插入图片描述
在这里插入图片描述
随便选择一个需要的,注意勾选移除d后缀后有没有与原文件名不符,若不符可之后在.pro文件修改
在这里插入图片描述
在.pro中自动添加的内容:
在这里插入图片描述
-lflann_cpp-g:即flann_cpp-g.lib的添加

2、使用脚本批量添加

在整理PCL库时,两个目录下的debug.txt,release.txt,使用如下脚本,创建所需的字符串格式,即-l+lib名+\ +\n,eg. -lpcl_common \

#coding=utf-8
import pyperclip


def forQt(file=""):
    with open(file) as f:
        text=f.readlines()
        text=[x.strip(".lib\n") for x in text]
        text=["\t-l"+x+" \\"+"\n" for x in text]
        text="".join(text)
        #将内容复制到粘贴板
        pyperclip.copy(text)


if __name__=="__main__":
    forQt("release.txt")   
    #forQt("debug.txt") 

分别对PCL 1.11.1\3rdParty\VTK\lib和PCL 1.11.1\lib下的debug.txt,release.txt使用,将结果粘贴到.pro文件的对应位置
(release,debug|release):release模式下的附加依赖项
(debug,debug|release): debug模式下的附加依赖项

然后修改
在这里插入图片描述

在这里插入图片描述

4、最终的.pro文件

直接粘贴注意修改目录

QT -= gui

CONFIG += c++11 console
CONFIG -= app_bundle

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
        main.cpp

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

INCLUDEPATH +=G:\c++_code\lib_3d\pcl\inc

#LIBS +=-L"G:\c++_code\lib_3d\pcl\lib"
win32:CONFIG(release, debug|release): LIBS +=-L"G:\c++_code\lib_3d\pcl\lib"
else:win32:CONFIG(debug, debug|release): LIBS +=-L"G:\c++_code\lib_3d\pcl\lib"

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../c++_code/lib_3d/pcl/lib/ \
    -lpcl_common \
    -lpcl_features \
    -lpcl_filters \
    -lpcl_io \
    -lpcl_io_ply \
    -lpcl_kdtree \
    -lpcl_keypoints \
    -lpcl_ml \
    -lpcl_octree \
    -lpcl_outofcore \
    -lpcl_people \
    -lpcl_recognition \
    -lpcl_registration \
    -lpcl_sample_consensus \
    -lpcl_search \
    -lpcl_segmentation \
    -lpcl_stereo \
    -lpcl_surface \
    -lpcl_tracking \
    -lpcl_visualization \
    -lvtkChartsCore-8.2 \
    -lvtkCommonColor-8.2 \
    -lvtkCommonComputationalGeometry-8.2 \
    -lvtkCommonCore-8.2 \
    -lvtkCommonDataModel-8.2 \
    -lvtkCommonExecutionModel-8.2 \
    -lvtkCommonMath-8.2 \
    -lvtkCommonMisc-8.2 \
    -lvtkCommonSystem-8.2 \
    -lvtkCommonTransforms-8.2 \
    -lvtkDICOMParser-8.2 \
    -lvtkDomainsChemistry-8.2 \
    -lvtkDomainsChemistryOpenGL2-8.2 \
    -lvtkdoubleconversion-8.2 \
    -lvtkexodusII-8.2 \
    -lvtkexpat-8.2 \
    -lvtkFiltersAMR-8.2 \
    -lvtkFiltersCore-8.2 \
    -lvtkFiltersExtraction-8.2 \
    -lvtkFiltersFlowPaths-8.2 \
    -lvtkFiltersGeneral-8.2 \
    -lvtkFiltersGeneric-8.2 \
    -lvtkFiltersGeometry-8.2 \
    -lvtkFiltersHybrid-8.2 \
    -lvtkFiltersHyperTree-8.2 \
    -lvtkFiltersImaging-8.2 \
    -lvtkFiltersModeling-8.2 \
    -lvtkFiltersParallel-8.2 \
    -lvtkFiltersParallelImaging-8.2 \
    -lvtkFiltersPoints-8.2 \
    -lvtkFiltersProgrammable-8.2 \
    -lvtkFiltersSelection-8.2 \
    -lvtkFiltersSMP-8.2 \
    -lvtkFiltersSources-8.2 \
    -lvtkFiltersStatistics-8.2 \
    -lvtkFiltersTexture-8.2 \
    -lvtkFiltersTopology-8.2 \
    -lvtkFiltersVerdict-8.2 \
    -lvtkfreetype-8.2 \
    -lvtkGeovisCore-8.2 \
    -lvtkgl2ps-8.2 \
    -lvtkglew-8.2 \
    -lvtkGUISupportMFC-8.2 \
    -lvtkhdf5-8.2 \
    -lvtkhdf5_hl-8.2 \
    -lvtkImagingColor-8.2 \
    -lvtkImagingCore-8.2 \
    -lvtkImagingFourier-8.2 \
    -lvtkImagingGeneral-8.2 \
    -lvtkImagingHybrid-8.2 \
    -lvtkImagingMath-8.2 \
    -lvtkImagingMorphological-8.2 \
    -lvtkImagingSources-8.2 \
    -lvtkImagingStatistics-8.2 \
    -lvtkImagingStencil-8.2 \
    -lvtkInfovisCore-8.2 \
    -lvtkInfovisLayout-8.2 \
    -lvtkInteractionImage-8.2 \
    -lvtkInteractionStyle-8.2 \
    -lvtkInteractionWidgets-8.2 \
    -lvtkIOAMR-8.2 \
    -lvtkIOAsynchronous-8.2 \
    -lvtkIOCityGML-8.2 \
    -lvtkIOCore-8.2 \
    -lvtkIOEnSight-8.2 \
    -lvtkIOExodus-8.2 \
    -lvtkIOExport-8.2 \
    -lvtkIOExportOpenGL2-8.2 \
    -lvtkIOExportPDF-8.2 \
    -lvtkIOGeometry-8.2 \
    -lvtkIOImage-8.2 \
    -lvtkIOImport-8.2 \
    -lvtkIOInfovis-8.2 \
    -lvtkIOLegacy-8.2 \
    -lvtkIOLSDyna-8.2 \
    -lvtkIOMINC-8.2 \
    -lvtkIOMovie-8.2 \
    -lvtkIONetCDF-8.2 \
    -lvtkIOParallel-8.2 \
    -lvtkIOParallelXML-8.2 \
    -lvtkIOPLY-8.2 \
    -lvtkIOSegY-8.2 \
    -lvtkIOSQL-8.2 \
    -lvtkIOTecplotTable-8.2 \
    -lvtkIOVeraOut-8.2 \
    -lvtkIOVideo-8.2 \
    -lvtkIOXML-8.2 \
    -lvtkIOXMLParser-8.2 \
    -lvtkjpeg-8.2 \
    -lvtkjsoncpp-8.2 \
    -lvtklibharu-8.2 \
    -lvtklibxml2-8.2 \
    -lvtklz4-8.2 \
    -lvtklzma-8.2 \
    -lvtkmetaio-8.2 \
    -lvtkNetCDF-8.2 \
    -lvtkogg-8.2 \
    -lvtkParallelCore-8.2 \
    -lvtkpng-8.2 \
    -lvtkproj-8.2 \
    -lvtkpugixml-8.2 \
    -lvtkRenderingAnnotation-8.2 \
    -lvtkRenderingContext2D-8.2 \
    -lvtkRenderingContextOpenGL2-8.2 \
    -lvtkRenderingCore-8.2 \
    -lvtkRenderingExternal-8.2 \
    -lvtkRenderingFreeType-8.2 \
    -lvtkRenderingGL2PSOpenGL2-8.2 \
    -lvtkRenderingImage-8.2 \
    -lvtkRenderingLabel-8.2 \
    -lvtkRenderingLOD-8.2 \
    -lvtkRenderingOpenGL2-8.2 \
    -lvtkRenderingVolume-8.2 \
    -lvtkRenderingVolumeOpenGL2-8.2 \
    -lvtksqlite-8.2 \
    -lvtksys-8.2 \
    -lvtktheora-8.2 \
    -lvtktiff-8.2 \
    -lvtkverdict-8.2 \
    -lvtkViewsContext2D-8.2 \
    -lvtkViewsCore-8.2 \
    -lvtkViewsInfovis-8.2 \
    -lvtkzlib-8.2 \


else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../c++_code/lib_3d/pcl/lib/ \
    -lpcl_commond \
    -lpcl_featuresd \
    -lpcl_filtersd \
    -lpcl_iod \
    -lpcl_io_plyd \
    -lpcl_kdtreed \
    -lpcl_keypointsd \
    -lpcl_mld \
    -lpcl_octreed \
    -lpcl_outofcored \
    -lpcl_peopled \
    -lpcl_recognitiond \
    -lpcl_registrationd \
    -lpcl_sample_consensusd \
    -lpcl_searchd \
    -lpcl_segmentationd \
    -lpcl_stereod \
    -lpcl_surfaced \
    -lpcl_trackingd \
    -lpcl_visualizationd \
    -lvtkChartsCore-8.2-gd \
    -lvtkCommonColor-8.2-gd \
    -lvtkCommonComputationalGeometry-8.2-gd \
    -lvtkCommonCore-8.2-gd \
    -lvtkCommonDataModel-8.2-gd \
    -lvtkCommonExecutionModel-8.2-gd \
    -lvtkCommonMath-8.2-gd \
    -lvtkCommonMisc-8.2-gd \
    -lvtkCommonSystem-8.2-gd \
    -lvtkCommonTransforms-8.2-gd \
    -lvtkDICOMParser-8.2-gd \
    -lvtkDomainsChemistry-8.2-gd \
    -lvtkDomainsChemistryOpenGL2-8.2-gd \
    -lvtkdoubleconversion-8.2-gd \
    -lvtkexodusII-8.2-gd \
    -lvtkexpat-8.2-gd \
    -lvtkFiltersAMR-8.2-gd \
    -lvtkFiltersCore-8.2-gd \
    -lvtkFiltersExtraction-8.2-gd \
    -lvtkFiltersFlowPaths-8.2-gd \
    -lvtkFiltersGeneral-8.2-gd \
    -lvtkFiltersGeneric-8.2-gd \
    -lvtkFiltersGeometry-8.2-gd \
    -lvtkFiltersHybrid-8.2-gd \
    -lvtkFiltersHyperTree-8.2-gd \
    -lvtkFiltersImaging-8.2-gd \
    -lvtkFiltersModeling-8.2-gd \
    -lvtkFiltersParallel-8.2-gd \
    -lvtkFiltersParallelImaging-8.2-gd \
    -lvtkFiltersPoints-8.2-gd \
    -lvtkFiltersProgrammable-8.2-gd \
    -lvtkFiltersSelection-8.2-gd \
    -lvtkFiltersSMP-8.2-gd \
    -lvtkFiltersSources-8.2-gd \
    -lvtkFiltersStatistics-8.2-gd \
    -lvtkFiltersTexture-8.2-gd \
    -lvtkFiltersTopology-8.2-gd \
    -lvtkFiltersVerdict-8.2-gd \
    -lvtkfreetype-8.2-gd \
    -lvtkGeovisCore-8.2-gd \
    -lvtkgl2ps-8.2-gd \
    -lvtkglew-8.2-gd \
    -lvtkGUISupportMFC-8.2-gd \
    -lvtkhdf5-8.2-gd \
    -lvtkhdf5_hl-8.2-gd \
    -lvtkImagingColor-8.2-gd \
    -lvtkImagingCore-8.2-gd \
    -lvtkImagingFourier-8.2-gd \
    -lvtkImagingGeneral-8.2-gd \
    -lvtkImagingHybrid-8.2-gd \
    -lvtkImagingMath-8.2-gd \
    -lvtkImagingMorphological-8.2-gd \
    -lvtkImagingSources-8.2-gd \
    -lvtkImagingStatistics-8.2-gd \
    -lvtkImagingStencil-8.2-gd \
    -lvtkInfovisCore-8.2-gd \
    -lvtkInfovisLayout-8.2-gd \
    -lvtkInteractionImage-8.2-gd \
    -lvtkInteractionStyle-8.2-gd \
    -lvtkInteractionWidgets-8.2-gd \
    -lvtkIOAMR-8.2-gd \
    -lvtkIOAsynchronous-8.2-gd \
    -lvtkIOCityGML-8.2-gd \
    -lvtkIOCore-8.2-gd \
    -lvtkIOEnSight-8.2-gd \
    -lvtkIOExodus-8.2-gd \
    -lvtkIOExport-8.2-gd \
    -lvtkIOExportOpenGL2-8.2-gd \
    -lvtkIOExportPDF-8.2-gd \
    -lvtkIOGeometry-8.2-gd \
    -lvtkIOImage-8.2-gd \
    -lvtkIOImport-8.2-gd \
    -lvtkIOInfovis-8.2-gd \
    -lvtkIOLegacy-8.2-gd \
    -lvtkIOLSDyna-8.2-gd \
    -lvtkIOMINC-8.2-gd \
    -lvtkIOMovie-8.2-gd \
    -lvtkIONetCDF-8.2-gd \
    -lvtkIOParallel-8.2-gd \
    -lvtkIOParallelXML-8.2-gd \
    -lvtkIOPLY-8.2-gd \
    -lvtkIOSegY-8.2-gd \
    -lvtkIOSQL-8.2-gd \
    -lvtkIOTecplotTable-8.2-gd \
    -lvtkIOVeraOut-8.2-gd \
    -lvtkIOVideo-8.2-gd \
    -lvtkIOXML-8.2-gd \
    -lvtkIOXMLParser-8.2-gd \
    -lvtkjpeg-8.2-gd \
    -lvtkjsoncpp-8.2-gd \
    -lvtklibharu-8.2-gd \
    -lvtklibharu-8.2 \
    -lvtklibxml2-8.2-gd \
    -lvtklibxml2-8.2 \
    -lvtklz4-8.2-gd \
    -lvtklzma-8.2-gd \
    -lvtkmetaio-8.2-gd \
    -lvtkNetCDF-8.2-gd \
    -lvtkogg-8.2-gd \
    -lvtkParallelCore-8.2-gd \
    -lvtkpng-8.2-gd \
    -lvtkproj-8.2-gd \
    -lvtkpugixml-8.2-gd \
    -lvtkRenderingAnnotation-8.2-gd \
    -lvtkRenderingContext2D-8.2-gd \
    -lvtkRenderingContextOpenGL2-8.2-gd \
    -lvtkRenderingCore-8.2-gd \
    -lvtkRenderingExternal-8.2-gd \
    -lvtkRenderingFreeType-8.2-gd \
    -lvtkRenderingGL2PSOpenGL2-8.2-gd \
    -lvtkRenderingImage-8.2-gd \
    -lvtkRenderingLabel-8.2-gd \
    -lvtkRenderingLOD-8.2-gd \
    -lvtkRenderingOpenGL2-8.2-gd \
    -lvtkRenderingVolume-8.2-gd \
    -lvtkRenderingVolumeOpenGL2-8.2-gd \
    -lvtksqlite-8.2-gd \
    -lvtksys-8.2-gd \
    -lvtktheora-8.2-gd \
    -lvtktiff-8.2-gd \
    -lvtkverdict-8.2-gd \
    -lvtkViewsContext2D-8.2-gd \
    -lvtkViewsCore-8.2-gd \
    -lvtkViewsInfovis-8.2-gd \
    -lvtkzlib-8.2-gd \
    -lvtkzlib-8.2 \

INCLUDEPATH += $$PWD/../../c++_code/lib_3d/pcl
DEPENDPATH += $$PWD/../../c++_code/lib_3d/pcl


三、测试

1、在main中添加一段pcl的官方示例代码

#include <iostream>

#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/point_cloud.h>
#include <pcl/console/parse.h>
#include <pcl/common/transforms.h>
#include <pcl/visualization/pcl_visualizer.h>
//#include <boost/iterator/function_output_iterator.hpp>

// This function displays the help
void
showHelp(char * program_name)
{
  std::cout << std::endl;
  std::cout << "Usage: " << program_name << " cloud_filename.[pcd|ply]" << std::endl;
  std::cout << "-h:  Show this help." << std::endl;
}

// This is the main function
int main (int argc, char** argv)
{

  // Show help
  if (pcl::console::find_switch (argc, argv, "-h") || pcl::console::find_switch (argc, argv, "--help")) {
    showHelp (argv[0]);
    return 0;
  }

  // Fetch point cloud filename in arguments | Works with PCD and PLY files
  std::vector<int> filenames;
  bool file_is_pcd = false;

  filenames = pcl::console::parse_file_extension_argument (argc, argv, ".ply");

  if (filenames.size () != 1)  {
    filenames = pcl::console::parse_file_extension_argument (argc, argv, ".pcd");

    if (filenames.size () != 1) {
      showHelp (argv[0]);
      return -1;
    } else {
      file_is_pcd = true;
    }
  }

  // Load file | Works with PCD and PLY files
  pcl::PointCloud<pcl::PointXYZ>::Ptr source_cloud (new pcl::PointCloud<pcl::PointXYZ> ());

  if (file_is_pcd) {
    if (pcl::io::loadPCDFile (argv[filenames[0]], *source_cloud) < 0)  {
      std::cout << "Error loading point cloud " << argv[filenames[0]] << std::endl << std::endl;
      showHelp (argv[0]);
      return -1;
    }
  } else {
    if (pcl::io::loadPLYFile (argv[filenames[0]], *source_cloud) < 0)  {
      std::cout << "Error loading point cloud " << argv[filenames[0]] << std::endl << std::endl;
      showHelp (argv[0]);
      return -1;
    }
  }

  /* Reminder: how transformation matrices work :

           |-------> This column is the translation
    | 1 0 0 x |  \
    | 0 1 0 y |   }-> The identity 3x3 matrix (no rotation) on the left
    | 0 0 1 z |  /
    | 0 0 0 1 |    -> We do not use this line (and it has to stay 0,0,0,1)

    METHOD #1: Using a Matrix4f
    This is the "manual" method, perfect to understand but error prone !
  */
  Eigen::Matrix4f transform_1 = Eigen::Matrix4f::Identity();

  // Define a rotation matrix (see https://en.wikipedia.org/wiki/Rotation_matrix)
  float theta = M_PI/4; // The angle of rotation in radians
  transform_1 (0,0) = std::cos (theta);
  transform_1 (0,1) = -sin(theta);
  transform_1 (1,0) = sin (theta);
  transform_1 (1,1) = std::cos (theta);
  //    (row, column)

  // Define a translation of 2.5 meters on the x axis.
  transform_1 (0,3) = 2.5;

  // Print the transformation
  printf ("Method #1: using a Matrix4f\n");
  std::cout << transform_1 << std::endl;

  /*  METHOD #2: Using a Affine3f
    This method is easier and less error prone
  */
  Eigen::Affine3f transform_2 = Eigen::Affine3f::Identity();

  // Define a translation of 2.5 meters on the x axis.
  transform_2.translation() << 2.5, 0.0, 0.0;

  // The same rotation matrix as before; theta radians around Z axis
  transform_2.rotate (Eigen::AngleAxisf (theta, Eigen::Vector3f::UnitZ()));

  // Print the transformation
  printf ("\nMethod #2: using an Affine3f\n");
  std::cout << transform_2.matrix() << std::endl;

  // Executing the transformation
  pcl::PointCloud<pcl::PointXYZ>::Ptr transformed_cloud (new pcl::PointCloud<pcl::PointXYZ> ());
  // You can either apply transform_1 or transform_2; they are the same
  pcl::transformPointCloud (*source_cloud, *transformed_cloud, transform_2);

  // Visualization
  printf(  "\nPoint cloud colors :  white  = original point cloud\n"
      "                        red  = transformed point cloud\n");
  pcl::visualization::PCLVisualizer viewer ("Matrix transformation example");

   // Define R,G,B colors for the point cloud
  pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> source_cloud_color_handler (source_cloud, 255, 255, 255);
  // We add the point cloud to the viewer and pass the color handler
  viewer.addPointCloud (source_cloud, source_cloud_color_handler, "original_cloud");

  pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> transformed_cloud_color_handler (transformed_cloud, 230, 20, 20); // Red
  viewer.addPointCloud (transformed_cloud, transformed_cloud_color_handler, "transformed_cloud");

  viewer.addCoordinateSystem (1.0, "cloud", 0);
  viewer.setBackgroundColor(0.05, 0.05, 0.05, 0); // Setting background to a dark grey
  viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "original_cloud");
  viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "transformed_cloud");
  //viewer.setPosition(800, 400); // Setting visualiser window position

  while (!viewer.wasStopped ()) { // Display the visualiser until 'q' key is pressed
    viewer.spinOnce ();
  }

  return 0;
}

2、输出

在这里插入图片描述
release下
在这里插入图片描述
debug下
在这里插入图片描述

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值