win10系统visual studio 2017安装PCL及环境变量--永久性配置

win10系统visual studio 2017安装PCL及环境变量–永久性配置@TOC

win10系统visual studio 2017安装PCL及环境变量–永久性配置

由于工作的需要终于还是要逼着自己学习win10系统下的PCL编程,但是刚开始总会遇到各种麻烦,现在做一个总结。

一.win10下安装PCL

  1. 下载pcl安装包:https://github.com/PointCloudLibrary/pcl/releases/tag/pcl-1.8.1
    win10系统visual studio 2017安装PCL及环境变量--永久性配置

下载相应的版本,其中msvc2017代表的是Microsoft visual studio 2017版本的,所以下载时要看清楚自己系统上相应的版本

2.把下载的两个文件放到同一个文件夹下,解压并安装,安装视频可以参考: https://www.bilibili.com/video/BV1SD4y197x8
win10系统visual studio 2017安装PCL及环境变量--永久性配置

二.永久配置

1.针对win10系统下进行永久配置pcl的视频可以参考:https://www.bilibili.com/video/BV1UK4y1Q7q3

在安装完pcl和visual studio 2017之后,打开vs2017–>文件–>新建项目–>空项目–>更改项目名称–>确定。
win10系统visual studio 2017安装PCL及环境变量--永久性配置
接下来从打开“属性管理器”:视图–>其他窗口–>属性管理器
win10系统visual studio 2017安装PCL及环境变量--永久性配置
在属性管理器中打开Microsoft.Cpp.x64.usr进行环境变量的配置(在这里只要配置好就可以应用到别的项目中去,不需要每次新建项目的时候需要进行环境变量的配置)
****************************************************************************************************

1.打开:通用属性–>VC++目录–>包含目录和库目录,分别编辑添加如下设置:
win10系统visual studio 2017安装PCL及环境变量--永久性配置

//选择VC++目录,选择包含目录添加包含的文件:
D:\PCL 1.8.1\include\pcl-1.8
D:\PCL 1.8.1\3rdParty\VTK\include\vtk-8.0
D:\PCL 1.8.1\3rdParty\Qhull\include
D:\PCL 1.8.1\3rdParty\OpenNI2\Include
D:\PCL 1.8.1\3rdParty\FLANN\include
D:\PCL 1.8.1\3rdParty\Eigen\eigen3
D:\PCL 1.8.1\3rdParty\Boost\include\boost-1_64

//设置库目录:
D:\PCL 1.8.1\3rdParty\Boost\lib
D:\PCL 1.8.1\3rdParty\FLANN\lib
D:\PCL 1.8.1\lib
D:\PCL 1.8.1\3rdParty\Qhull\lib
D:\PCL 1.8.1\3rdParty\VTK\lib

2.打开: 通用属性–>连接器–>输入–>附加依赖项,编辑添加如下设置,应用并确定:
参考链接:https://www.cnblogs.com/li-yao7758258/p/8066352.html
(****在退出时选择是否继承父系,点击“是”即可)
win10系统visual studio 2017安装PCL及环境变量--永久性配置

//附加依赖项
vtknetcdf_c++-gd.lib;
pcl_common_debug.lib;
pcl_features_debug.lib;
pcl_filters_debug.lib;
pcl_io_ply_debug.lib;
pcl_io_debug.lib;
pcl_kdtree_debug.lib;
pcl_keypoints_debug.lib;
pcl_ml_debug.lib;
pcl_octree_debug.lib;
pcl_outofcore_debug.lib;
pcl_people_debug.lib;
pcl_recognition_debug.lib;
pcl_registration_debug.lib;
pcl_sample_consensus_debug.lib;
pcl_search_debug.lib;
pcl_segmentation_debug.lib;
pcl_stereo_debug.lib;
pcl_surface_debug.lib;
pcl_tracking_debug.lib;
pcl_visualization_debug.lib;
libboost_atomic-vc141-mt-gd-1_64.lib;
libboost_bzip2-vc141-mt-gd-1_64.lib;
libboost_chrono-vc141-mt-gd-1_64.lib;
libboost_container-vc141-mt-gd-1_64.lib;
libboost_context-vc141-mt-gd-1_64.lib;
libboost_coroutine-vc141-mt-gd-1_64.lib;
libboost_date_time-vc141-mt-gd-1_64.lib;
libboost_exception-vc141-mt-gd-1_64.lib;
libboost_fiber-vc141-mt-gd-1_64.lib;
libboost_filesystem-vc141-mt-gd-1_64.lib;
libboost_graph-vc141-mt-gd-1_64.lib;
libboost_graph_parallel-vc141-mt-gd-1_64.lib;
libboost_iostreams-vc141-mt-gd-1_64.lib;
libboost_locale-vc141-mt-gd-1_64.lib;
libboost_log-vc141-mt-gd-1_64.lib;
libboost_log_setup-vc141-mt-gd-1_64.lib;
libboost_math_c99-vc141-mt-gd-1_64.lib;
libboost_math_c99f-vc141-mt-gd-1_64.lib;
libboost_math_c99l-vc141-mt-gd-1_64.lib;
libboost_math_tr1-vc141-mt-gd-1_64.lib;
libboost_math_tr1f-vc141-mt-gd-1_64.lib;
libboost_math_tr1l-vc141-mt-gd-1_64.lib;
libboost_mpi-vc141-mt-gd-1_64.lib;
libboost_numpy3-vc141-mt-gd-1_64.lib;
libboost_numpy-vc141-mt-gd-1_64.lib;
libboost_prg_exec_monitor-vc141-mt-gd-1_64.lib;
libboost_program_options-vc141-mt-gd-1_64.lib;
libboost_python3-vc141-mt-gd-1_64.lib;
libboost_python-vc141-mt-gd-1_64.lib;
libboost_random-vc141-mt-gd-1_64.lib;
libboost_regex-vc141-mt-gd-1_64.lib;
libboost_serialization-vc141-mt-gd-1_64.lib;
libboost_signals-vc141-mt-gd-1_64.lib;
libboost_system-vc141-mt-gd-1_64.lib;
libboost_test_exec_monitor-vc141-mt-gd-1_64.lib;
libboost_thread-vc141-mt-gd-1_64.lib;
libboost_timer-vc141-mt-gd-1_64.lib;
libboost_type_erasure-vc141-mt-gd-1_64.lib;
libboost_unit_test_framework-vc141-mt-gd-1_64.lib;
libboost_wave-vc141-mt-gd-1_64.lib;
libboost_wserialization-vc141-mt-gd-1_64.lib;
libboost_zlib-vc141-mt-gd-1_64.lib;
flann-gd.lib;
flann_cpp-gd.lib;
flann_cpp_s-gd.lib;
flann_s-gd.lib;
qhull_d.lib;
qhullcpp_d.lib;
qhullstatic_d.lib;
qhullstatic_r_d.lib;
qhull_p_d.lib;
qhull_r_d.lib;
vtkalglib-8.0-gd.lib;
vtkChartsCore-8.0-gd.lib;
vtkCommonColor-8.0-gd.lib;
vtkCommonComputationalGeometry-8.0-gd.lib;
vtkCommonCore-8.0-gd.lib;
vtkCommonDataModel-8.0-gd.lib;
vtkCommonExecutionModel-8.0-gd.lib;
vtkCommonMath-8.0-gd.lib;
vtkCommonMisc-8.0-gd.lib;
vtkCommonSystem-8.0-gd.lib;
vtkCommonTransforms-8.0-gd.lib;
vtkDICOMParser-8.0-gd.lib;
vtkDomainsChemistry-8.0-gd.lib;
vtkexoIIc-8.0-gd.lib;
vtkexpat-8.0-gd.lib;
vtkFiltersAMR-8.0-gd.lib;
vtkFiltersCore-8.0-gd.lib;
vtkFiltersExtraction-8.0-gd.lib;
vtkFiltersFlowPaths-8.0-gd.lib;
vtkFiltersGeneral-8.0-gd.lib;
vtkFiltersGeneric-8.0-gd.lib;
vtkFiltersGeometry-8.0-gd.lib;
vtkFiltersHybrid-8.0-gd.lib;
vtkFiltersHyperTree-8.0-gd.lib;
vtkFiltersImaging-8.0-gd.lib;
vtkFiltersModeling-8.0-gd.lib;
vtkFiltersParallel-8.0-gd.lib;
vtkFiltersParallelImaging-8.0-gd.lib;
vtkFiltersPoints-8.0-gd.lib;
vtkFiltersProgrammable-8.0-gd.lib;
vtkFiltersSelection-8.0-gd.lib;
vtkFiltersSMP-8.0-gd.lib;
vtkFiltersSources-8.0-gd.lib;
vtkFiltersStatistics-8.0-gd.lib;
vtkFiltersTexture-8.0-gd.lib;
vtkFiltersTopology-8.0-gd.lib;
vtkFiltersVerdict-8.0-gd.lib;
vtkfreetype-8.0-gd.lib;
vtkGeovisCore-8.0-gd.lib;
vtkgl2ps-8.0-gd.lib;
vtkhdf5-8.0-gd.lib;
vtkhdf5_hl-8.0-gd.lib;
vtkImagingColor-8.0-gd.lib;
vtkImagingCore-8.0-gd.lib;
vtkImagingFourier-8.0-gd.lib;
vtkImagingGeneral-8.0-gd.lib;
vtkImagingHybrid-8.0-gd.lib;
vtkImagingMath-8.0-gd.lib;
vtkImagingMorphological-8.0-gd.lib;
vtkImagingSources-8.0-gd.lib;
vtkImagingStatistics-8.0-gd.lib;
vtkImagingStencil-8.0-gd.lib;
vtkInfovisCore-8.0-gd.lib;
vtkInfovisLayout-8.0-gd.lib;
vtkInteractionImage-8.0-gd.lib;
vtkInteractionStyle-8.0-gd.lib;
vtkInteractionWidgets-8.0-gd.lib;
vtkIOAMR-8.0-gd.lib;
vtkIOCore-8.0-gd.lib;
vtkIOEnSight-8.0-gd.lib;
vtkIOExodus-8.0-gd.lib;
vtkIOExport-8.0-gd.lib;
vtkIOExportOpenGL-8.0-gd.lib;
vtkIOGeometry-8.0-gd.lib;
vtkIOImage-8.0-gd.lib;
vtkIOImport-8.0-gd.lib;
vtkIOInfovis-8.0-gd.lib;
vtkIOLegacy-8.0-gd.lib;
vtkIOLSDyna-8.0-gd.lib;
vtkIOMINC-8.0-gd.lib;
vtkIOMovie-8.0-gd.lib;
vtkIONetCDF-8.0-gd.lib;
vtkIOParallel-8.0-gd.lib;
vtkIOParallelXML-8.0-gd.lib;
vtkIOPLY-8.0-gd.lib;
vtkIOSQL-8.0-gd.lib;
vtkIOTecplotTable-8.0-gd.lib;
vtkIOVideo-8.0-gd.lib;
vtkIOXML-8.0-gd.lib;
vtkIOXMLParser-8.0-gd.lib;
vtkjpeg-8.0-gd.lib;
vtkjsoncpp-8.0-gd.lib;
vtklibharu-8.0-gd.lib;
vtklibxml2-8.0-gd.lib;
vtklz4-8.0-gd.lib;
vtkmetaio-8.0-gd.lib;
vtkNetCDF-8.0-gd.lib;
vtkoggtheora-8.0-gd.lib;
vtkParallelCore-8.0-gd.lib;
vtkpng-8.0-gd.lib;
vtkproj4-8.0-gd.lib;
vtkRenderingAnnotation-8.0-gd.lib;
vtkRenderingContext2D-8.0-gd.lib;
vtkRenderingContextOpenGL-8.0-gd.lib;
vtkRenderingCore-8.0-gd.lib;
vtkRenderingFreeType-8.0-gd.lib;
vtkRenderingGL2PS-8.0-gd.lib;
vtkRenderingImage-8.0-gd.lib;
vtkRenderingLabel-8.0-gd.lib;
vtkRenderingLIC-8.0-gd.lib;
vtkRenderingLOD-8.0-gd.lib;
vtkRenderingOpenGL-8.0-gd.lib;
vtkRenderingVolume-8.0-gd.lib;
vtkRenderingVolumeOpenGL-8.0-gd.lib;
vtksqlite-8.0-gd.lib;
vtksys-8.0-gd.lib;
vtktiff-8.0-gd.lib;
vtkverdict-8.0-gd.lib;
vtkViewsContext2D-8.0-gd.lib;
vtkViewsCore-8.0-gd.lib;
vtkViewsInfovis-8.0-gd.lib;
vtkzlib-8.0-gd.lib;
opengl32.lib;

三、开始自己的新项目

1.新建自己的新项目:在解决方案管理器–>源文件–>添加–>新建项–>c++文件。
win10系统visual studio 2017安装PCL及环境变量--永久性配置
win10系统visual studio 2017安装PCL及环境变量--永久性配置
2.把自己的代码写进去即可,生成并调试。
下面是pcl官网中Registration的一个点云配准的一个例子,官网:https://pcl.readthedocs.io/projects/tutorials/en/latest/pairwise_incremental_registration.html#pairwise-incremental-registration

/*
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2010, Willow Garage, Inc.
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of Willow Garage, Inc. nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *
 * $Id$
 *
 */

/* \author Radu Bogdan Rusu
 * adaptation Raphael Favier*/

//#include <pcl/memory.h>  // for pcl::make_shared 这行代码是针对高版本的
#include<boost/make_shared.hpp>  //for boost::make_shared 这行代码是针对1.8.1 版本使用 
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/point_representation.h>

#include <pcl/io/pcd_io.h>

#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/filter.h>

#include <pcl/features/normal_3d.h>

#include <pcl/registration/icp.h>
#include <pcl/registration/icp_nl.h>
#include <pcl/registration/transforms.h>

#include <pcl/visualization/pcl_visualizer.h>

using pcl::visualization::PointCloudColorHandlerGenericField;
using pcl::visualization::PointCloudColorHandlerCustom;

//convenient typedefs
typedef pcl::PointXYZ PointT;
typedef pcl::PointCloud<PointT> PointCloud;
typedef pcl::PointNormal PointNormalT;
typedef pcl::PointCloud<PointNormalT> PointCloudWithNormals;

// This is a tutorial so we can afford having global variables 
	//our visualizer
	pcl::visualization::PCLVisualizer *p;
	//its left and right viewports
	int vp_1, vp_2;

//convenient structure to handle our pointclouds
struct PCD
{
  PointCloud::Ptr cloud;
  std::string f_name;

  PCD() : cloud (new PointCloud) {};
};

struct PCDComparator
{
  bool operator () (const PCD& p1, const PCD& p2)
  {
    return (p1.f_name < p2.f_name);
  }
};


// Define a new point representation for < x, y, z, curvature >
class MyPointRepresentation : public pcl::PointRepresentation <PointNormalT>
{
  using pcl::PointRepresentation<PointNormalT>::nr_dimensions_;
public:
  MyPointRepresentation ()
  {
    // Define the number of dimensions
    nr_dimensions_ = 4;
  }

  // Override the copyToFloatArray method to define our feature vector
  virtual void copyToFloatArray (const PointNormalT &p, float * out) const
  {
    // < x, y, z, curvature >
    out[0] = p.x;
    out[1] = p.y;
    out[2] = p.z;
    out[3] = p.curvature;
  }
};



/** \brief Display source and target on the first viewport of the visualizer
 *
 */
void showCloudsLeft(const PointCloud::Ptr cloud_target, const PointCloud::Ptr cloud_source)
{
  p->removePointCloud ("vp1_target");
  p->removePointCloud ("vp1_source");

  PointCloudColorHandlerCustom<PointT> tgt_h (cloud_target, 0, 255, 0);
  PointCloudColorHandlerCustom<PointT> src_h (cloud_source, 255, 0, 0);
  p->addPointCloud (cloud_target, tgt_h, "vp1_target", vp_1);
  p->addPointCloud (cloud_source, src_h, "vp1_source", vp_1);

  PCL_INFO ("Press q to begin the registration.\n");
  p-> spin();
}



/** \brief Display source and target on the second viewport of the visualizer
 *
 */
void showCloudsRight(const PointCloudWithNormals::Ptr cloud_target, const PointCloudWithNormals::Ptr cloud_source)
{
  p->removePointCloud ("source");
  p->removePointCloud ("target");


  PointCloudColorHandlerGenericField<PointNormalT> tgt_color_handler (cloud_target, "curvature");
  if (!tgt_color_handler.isCapable ())
      PCL_WARN ("Cannot create curvature color handler!");

  PointCloudColorHandlerGenericField<PointNormalT> src_color_handler (cloud_source, "curvature");
  if (!src_color_handler.isCapable ())
      PCL_WARN ("Cannot create curvature color handler!");


  p->addPointCloud (cloud_target, tgt_color_handler, "target", vp_2);
  p->addPointCloud (cloud_source, src_color_handler, "source", vp_2);

  p->spinOnce();
}


/** \brief Load a set of PCD files that we want to register together
  * \param argc the number of arguments (pass from main ())
  * \param argv the actual command line arguments (pass from main ())
  * \param models the resultant vector of point cloud datasets
  */
void loadData (int argc, char **argv, std::vector<PCD, Eigen::aligned_allocator<PCD> > &models)
{
  std::string extension (".pcd");
  // Suppose the first argument is the actual test model
  for (int i = 1; i < argc; i++)
  {
    std::string fname = std::string (argv[i]);
    // Needs to be at least 5: .plot
    if (fname.size () <= extension.size ())
      continue;

    std::transform (fname.begin (), fname.end (), fname.begin (), (int(*)(int))tolower);

    //check that the argument is a pcd file
    if (fname.compare (fname.size () - extension.size (), extension.size (), extension) == 0)
    {
      // Load the cloud and saves it into the global list of models
      PCD m;
      m.f_name = argv[i];
      pcl::io::loadPCDFile (argv[i], *m.cloud);
      //remove NAN points from the cloud
      std::vector<int> indices;
      pcl::removeNaNFromPointCloud(*m.cloud,*m.cloud, indices);

      models.push_back (m);
    }
  }
}



/** \brief Align a pair of PointCloud datasets and return the result
  * \param cloud_src the source PointCloud
  * \param cloud_tgt the target PointCloud
  * \param output the resultant aligned source PointCloud
  * \param final_transform the resultant transform between source and target
  */
void pairAlign (const PointCloud::Ptr cloud_src, const PointCloud::Ptr cloud_tgt, PointCloud::Ptr output, Eigen::Matrix4f &final_transform, bool downsample = false)
{
  //
  // Downsample for consistency and speed
  // \note enable this for large datasets
  PointCloud::Ptr src (new PointCloud);
  PointCloud::Ptr tgt (new PointCloud);
  pcl::VoxelGrid<PointT> grid;
  if (downsample)
  {
    grid.setLeafSize (0.05, 0.05, 0.05);
    grid.setInputCloud (cloud_src);
    grid.filter (*src);

    grid.setInputCloud (cloud_tgt);
    grid.filter (*tgt);
  }
  else
  {
    src = cloud_src;
    tgt = cloud_tgt;
  }


  // Compute surface normals and curvature
  PointCloudWithNormals::Ptr points_with_normals_src (new PointCloudWithNormals);
  PointCloudWithNormals::Ptr points_with_normals_tgt (new PointCloudWithNormals);

  pcl::NormalEstimation<PointT, PointNormalT> norm_est;
  pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ> ());
  norm_est.setSearchMethod (tree);
  norm_est.setKSearch (30);
  
  norm_est.setInputCloud (src);
  norm_est.compute (*points_with_normals_src);
  pcl::copyPointCloud (*src, *points_with_normals_src);

  norm_est.setInputCloud (tgt);
  norm_est.compute (*points_with_normals_tgt);
  pcl::copyPointCloud (*tgt, *points_with_normals_tgt);

  //
  // Instantiate our custom point representation (defined above) ...
  MyPointRepresentation point_representation;
  // ... and weight the 'curvature' dimension so that it is balanced against x, y, and z
  float alpha[4] = {1.0, 1.0, 1.0, 1.0};
  point_representation.setRescaleValues (alpha);

  //
  // Align
  pcl::IterativeClosestPointNonLinear<PointNormalT, PointNormalT> reg;
  reg.setTransformationEpsilon (1e-6);
  // Set the maximum distance between two correspondences (src<->tgt) to 10cm
  // Note: adjust this based on the size of your datasets
  reg.setMaxCorrespondenceDistance (0.1);  
  // Set the point representation
  reg.setPointRepresentation (boost::make_shared<const MyPointRepresentation> (point_representation)); //1.8.1版本使用
  //reg.setPointRepresentation (pcl::make_shared<const MyPointRepresentation> (point_representation));//高版本使用

  reg.setInputSource (points_with_normals_src);
  reg.setInputTarget (points_with_normals_tgt);

  //
  // Run the same optimization in a loop and visualize the results
  Eigen::Matrix4f Ti = Eigen::Matrix4f::Identity (), prev, targetToSource;
  PointCloudWithNormals::Ptr reg_result = points_with_normals_src;
  reg.setMaximumIterations (2);
  for (int i = 0; i < 30; ++i)
  {
    PCL_INFO ("Iteration Nr. %d.\n", i);

    // save cloud for visualization purpose
    points_with_normals_src = reg_result;

    // Estimate
    reg.setInputSource (points_with_normals_src);
    reg.align (*reg_result);

		//accumulate transformation between each Iteration
    Ti = reg.getFinalTransformation () * Ti;

		//if the difference between this transformation and the previous one
		//is smaller than the threshold, refine the process by reducing
		//the maximal correspondence distance
    if (std::abs ((reg.getLastIncrementalTransformation () - prev).sum ()) < reg.getTransformationEpsilon ())
      reg.setMaxCorrespondenceDistance (reg.getMaxCorrespondenceDistance () - 0.001);
    
    prev = reg.getLastIncrementalTransformation ();

    // visualize current state
    showCloudsRight(points_with_normals_tgt, points_with_normals_src);
  }

	//
  // Get the transformation from target to source
  targetToSource = Ti.inverse();

  //
  // Transform target back in source frame
  pcl::transformPointCloud (*cloud_tgt, *output, targetToSource);

  p->removePointCloud ("source");
  p->removePointCloud ("target");

  PointCloudColorHandlerCustom<PointT> cloud_tgt_h (output, 0, 255, 0);
  PointCloudColorHandlerCustom<PointT> cloud_src_h (cloud_src, 255, 0, 0);
  p->addPointCloud (output, cloud_tgt_h, "target", vp_2);
  p->addPointCloud (cloud_src, cloud_src_h, "source", vp_2);

	PCL_INFO ("Press q to continue the registration.\n");
  p->spin ();

  p->removePointCloud ("source"); 
  p->removePointCloud ("target");

  //add the source to the transformed target
  *output += *cloud_src;
  
  final_transform = targetToSource;
 }


/* ---[ */
int main (int argc, char** argv)
{
  // Load data
  std::vector<PCD, Eigen::aligned_allocator<PCD> > data;
  loadData (argc, argv, data);

  // Check user input
  if (data.empty ())
  {
    PCL_ERROR ("Syntax is: %s <source.pcd> <target.pcd> [*]", argv[0]);
    PCL_ERROR ("[*] - multiple files can be added. The registration results of (i, i+1) will be registered against (i+2), etc");
    return (-1);
  }
  PCL_INFO ("Loaded %d datasets.", (int)data.size ());
  
  // Create a PCLVisualizer object
  p = new pcl::visualization::PCLVisualizer (argc, argv, "Pairwise Incremental Registration example");
  p->createViewPort (0.0, 0, 0.5, 1.0, vp_1);
  p->createViewPort (0.5, 0, 1.0, 1.0, vp_2);

	PointCloud::Ptr result (new PointCloud), source, target;
  Eigen::Matrix4f GlobalTransform = Eigen::Matrix4f::Identity (), pairTransform;
  
  for (std::size_t i = 1; i < data.size (); ++i)
  {
    source = data[i-1].cloud;
    target = data[i].cloud;

    // Add visualization data
    showCloudsLeft(source, target);

    PointCloud::Ptr temp (new PointCloud);
    PCL_INFO ("Aligning %s (%zu) with %s (%zu).\n", data[i-1].f_name.c_str (), static_cast<std::size_t>(source->size ()), data[i].f_name.c_str (), static_cast<std::size_t>(target->size ()));
    pairAlign (source, target, temp, pairTransform, true);

    //transform current pair into the global transform
    pcl::transformPointCloud (*temp, *result, GlobalTransform);

    //update the global transform
    GlobalTransform *= pairTransform;

    //save aligned pair, transformed into the first cloud's frame
    std::stringstream ss;
    ss << i << ".pcd";
    pcl::io::savePCDFile (ss.str (), *result, true);

  }
}
/* ]--- */

如果出现报错,有可能是选择debug模式下的x64环境下运行,如下:
win10系统visual studio 2017安装PCL及环境变量--永久性配置
3.此时生成并编译,但是由于这里运行时需要输入相对应的要进行配准的点云文件,所以在win10里还是麻烦的,需要到Windows PowerShell 上运行才行。如果运行出现以下错误,需要在项目属性下C/C+±->常规–>SDL检查中选择“否”即可。
win10系统visual studio 2017安装PCL及环境变量--永久性配置
win10系统visual studio 2017安装PCL及环境变量--永久性配置
win10系统visual studio 2017安装PCL及环境变量--永久性配置

#define BOOST_TYPEOF_EMULATION

win10系统visual studio 2017安装PCL及环境变量--永久性配置
4.到这里已经可以生成你自己的项目了,这里要运行出现跟pcl官网一样的效果就要下载相关的*.pcd文件进行编译。
下载pcd链接:https://github.com/PointCloudLibrary/data/tree/master/tutorials/pairwise
win10系统visual studio 2017安装PCL及环境变量--永久性配置
5.运行项目,找到自己项目的文件夹,按住shift键,右击空白处点击“在此处打开Powershell窗口”,输入你的项目的首个字母“P”,并按下“tab”键,在Powershell窗口上主动补全执行文件.exe的名称;接下来就是找到刚才下载的点云文件的文件夹,复制路径并把文件名称写上去(使用“tab”键)并回车即可运行:
win10系统visual studio 2017安装PCL及环境变量--永久性配置
win10系统visual studio 2017安装PCL及环境变量--永久性配置
6.按下"q"即可,最后只需要等待结果即可。
win10系统visual studio 2017安装PCL及环境变量--永久性配置
最后就是完成了自己的项目的运行啦!希望大家都好运,顺风顺水,做一个安静的程序猿,哈哈哈。

上一篇:DL之DNN优化技术:神经网络算法简介之GD/SGD算法的简介、代码实现、代码调参之详细攻略


下一篇:PCL点云库安装及学习(2021.7.28)