【PCL】mac下安装PCL的安装与配置

【PCL】mac下安装PCL的安装与配置

PCL

PCL官方文档

PCL(Point Cloud Library)是在吸收了前人点云相关研究基础上建立起来的大型跨平台开源C++编程库,它实现了大量点云相关的通用算法和高效数据结构,涉及到点云获取、滤波、分割、配准、检索、特征提取、识别、追踪、曲面重建、可视化等。支持多种操作系统平台,可在Windows、Linux、Android、Mac OS X、部分嵌入式实时系统上运行。如果说OpenCV是2D信息获取与处理的结晶,那么PCL就在3D信息获取与处理上具有同等地位,PCL是BSD授权方式,可以免费进行商业和学术应用。

通常在 windows 平台下安装 PCL 算是比较简单的,他的每一个版本都有一个 pcl 对应的的 AllInOne的一个安装的exe 软件 。或者也可以用 vcpkg 直接集成,但是mac下 安装的话更为简单。
PCL Download
github Download

第一步:安装homebrew

打开终端 输入

powershell 复制代码
ruby -e "$(curl --insecure -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 

接下来等待安装完毕即可

第二步:使用homebrew安装pcl

也很简单,打开终端,输入:

powershell 复制代码
brew install pcl

首先会安装PCL的相关依赖库,如vtk,glew等,最后安装pcl

第三步: PCL的编译

这一步是最麻烦的,由于之前更多地在Windows上进行开发,更没有接触过cmake,所以碰到了许多稀奇古怪的问题。

1. 在工程目录下(如Desktop/PCLtest/)新建文件CMakeLists.txt,在该文件中写入:

clike 复制代码
cmake_minimum_required(VERSION 3.0 FATAL_ERROR) # 选择cmake版本

project(PCLtest) # 给工程命名

find_package(PCL 1.4 REQUIRED COMPONENTS common io) # 使用find_package寻找指定版本PCL的指定模块,如果想导入全部模块,也可以写为 find_package(PCL REQUIRED) 

include_directories(${PCL_INCLUDE_DIRS})

link_directories(${PCL_LIBRARY_DIRS})

add_definitions(${PCL_DEFINITIONS})

add_executable(PCLtest main.cpp)

target_link_libraries(PCLtest ${PCL_LIBRARIES})

2. 在工程目录下新建文件main.cpp,并写入:

cpp 复制代码
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
 
int
  main (int argc, char** argv)
{
  pcl::PointCloud<pcl::PointXYZ> cloud;
 
  // Fill in the cloud data
  cloud.width    = 5;
  cloud.height   = 1;
  cloud.is_dense = false;
  cloud.points.resize (cloud.width * cloud.height);
 
  for (size_t i = 0; i < cloud.points.size (); ++i)
  {
    cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
  }
 
  pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
  std::cerr << "Saved " << cloud.points.size () << " data points to test_pcd.pcd." << std::endl;
 
  for (size_t i = 0; i < cloud.points.size (); ++i)
    std::cerr << "    " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;
 
  return (0);
}

3. 生成Cmake工程

在 CMakeLists.txt 同级目录下 (如Desktop/PCLtest)下 打开终端或者进入从家目录下进到这个目录

powershell 复制代码
cmake -S . -B build

4. 打开终端,进行编译

同样 同级目录

powershell 复制代码
cmake --build build

cmake后屏幕输出:

powershell 复制代码
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /Users/zhi/Desktop/PCLtest
-- The C compiler identification is AppleClang 10.0.1.10010046
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Checking for module 'eigen3'
--   Found eigen3, version 3.3.7
-- Found Eigen: /usr/local/include/eigen3  
-- Eigen found (include: /usr/local/include/eigen3, version: 3.3.7)
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE  
-- Boost version: 1.70.0
-- Found the following Boost libraries:
--   system
--   filesystem
--   thread
--   date_time
--   iostreams
--   serialization
--   chrono
--   atomic
--   regex
-- Checking for module 'flann'
--   Found flann, version 1.9.1
-- FLANN found (include: /usr/local/Cellar/flann/1.9.1_7/include, lib: flann;flann_cpp)
-- FLANN found (include: /usr/local/Cellar/flann/1.9.1_7/include, lib: flann;flann_cpp)
** WARNING ** io features related to pcap will be disabled
** WARNING ** io features related to png will be disabled
-- Found libusb-1.0: /usr/local/include  
** WARNING ** io features related to libusb-1.0 will be disabled
-- Found Qhull: optimized;/usr/local/lib/libqhull_p.dylib;debug;/usr/local/lib/libqhull_p.dylib  
-- QHULL found (include: /usr/local/include, lib: optimized;/usr/local/lib/libqhull_p.dylib;debug;/usr/local/lib/libqhull_p.dylib)
-- Found OpenGL: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework   
-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.29.2") 
-- Checking for module 'glew'
--   Found glew, version 2.1.0
-- Found Glew: GLEW;-framework Cocoa
-- looking for PCL_COMMON
-- Found PCL_COMMON: /usr/local/lib/libpcl_common.dylib  
-- looking for PCL_KDTREE
-- Found PCL_KDTREE: /usr/local/lib/libpcl_kdtree.dylib  
-- looking for PCL_OCTREE
-- Found PCL_OCTREE: /usr/local/lib/libpcl_octree.dylib  
-- looking for PCL_SEARCH
-- Found PCL_SEARCH: /usr/local/lib/libpcl_search.dylib  
-- looking for PCL_SAMPLE_CONSENSUS
-- Found PCL_SAMPLE_CONSENSUS: /usr/local/lib/libpcl_sample_consensus.dylib  
-- looking for PCL_FILTERS
-- Found PCL_FILTERS: /usr/local/lib/libpcl_filters.dylib  
-- looking for PCL_2D
-- Found PCL_2D: /usr/local/include/pcl-1.9  
-- looking for PCL_GEOMETRY
-- Found PCL_GEOMETRY: /usr/local/include/pcl-1.9  
-- looking for PCL_IO
-- Found PCL_IO: /usr/local/lib/libpcl_io.dylib  
-- looking for PCL_FEATURES
-- Found PCL_FEATURES: /usr/local/lib/libpcl_features.dylib  
-- looking for PCL_ML
-- Found PCL_ML: /usr/local/lib/libpcl_ml.dylib  
-- looking for PCL_SEGMENTATION
-- Found PCL_SEGMENTATION: /usr/local/lib/libpcl_segmentation.dylib  
-- looking for PCL_VISUALIZATION
-- Found PCL_VISUALIZATION: /usr/local/lib/libpcl_visualization.dylib  
-- looking for PCL_SURFACE
-- Found PCL_SURFACE: /usr/local/lib/libpcl_surface.dylib  
-- looking for PCL_REGISTRATION
-- Found PCL_REGISTRATION: /usr/local/lib/libpcl_registration.dylib  
-- looking for PCL_KEYPOINTS
-- Found PCL_KEYPOINTS: /usr/local/lib/libpcl_keypoints.dylib  
-- looking for PCL_TRACKING
-- Found PCL_TRACKING: /usr/local/lib/libpcl_tracking.dylib  
-- looking for PCL_RECOGNITION
-- Found PCL_RECOGNITION: /usr/local/lib/libpcl_recognition.dylib  
-- looking for PCL_STEREO
-- Found PCL_STEREO: /usr/local/lib/libpcl_stereo.dylib  
-- looking for PCL_APPS
-- Found PCL_APPS: /usr/local/lib/libpcl_apps.dylib  
-- looking for PCL_OUTOFCORE
-- Found PCL_OUTOFCORE: /usr/local/lib/libpcl_outofcore.dylib  
-- looking for PCL_PEOPLE
-- Found PCL_PEOPLE: /usr/local/lib/libpcl_people.dylib  
-- looking for PCL_SIMULATION
-- Found PCL_SIMULATION: /usr/local/lib/libpcl_simulation.dylib  
-- Found PCL: pcl_common;pcl_kdtree;pcl_octree;pcl_search;pcl_sample_consensus;pcl_filters;pcl_io;pcl_features;pcl_ml;pcl_segmentation;pcl_visualization;pcl_surface;pcl_registration;pcl_keypoints;pcl_tracking;pcl_recognition;pcl_stereo;pcl_apps;pcl_outofcore;pcl_people;pcl_simulation;/usr/local/lib/libboost_system-mt.dylib;/usr/local/lib/libboost_filesystem-mt.dylib;/usr/local/lib/libboost_thread-mt.dylib;/usr/local/lib/libboost_date_time-mt.dylib;/usr/local/lib/libboost_iostreams-mt.dylib;/usr/local/lib/libboost_serialization-mt.dylib;/usr/local/lib/libboost_chrono-mt.dylib;/usr/local/lib/libboost_atomic-mt.dylib;/usr/local/lib/libboost_regex-mt.dylib;optimized;/usr/local/lib/libqhull_p.dylib;debug;/usr/local/lib/libqhull_p.dylib;flann;flann_cpp;vtksys;vtkCommonCore;vtkCommonMath;vtkCommonMisc;vtkCommonSystem;vtkCommonTransforms;vtkCommonDataModel;vtkCommonColor;vtkCommonExecutionModel;vtkCommonComputationalGeometry;vtkFiltersCore;vtkFiltersGeneral;vtkImagingCore;vtkImagingFourier;vtkFiltersStatistics;vtkFiltersExtraction;vtkInfovisCore;vtkFiltersGeometry;vtkFiltersSources;vtkRenderingCore;/usr/lib/libz.dylib;vtkfreetype;vtkRenderingFreeType;vtkRenderingContext2D;vtkChartsCore;vtkDICOMParser;vtkdoubleconversion;vtklz4;vtklzma;vtkIOCore;vtkIOLegacy;/usr/lib/libexpat.dylib;vtkIOXMLParser;vtkDomainsChemistry;vtkglew;vtkRenderingOpenGL2;vtkDomainsChemistryOpenGL2;vtkIOXML;vtkParallelCore;vtkFiltersAMR;vtkFiltersFlowPaths;vtkFiltersGeneric;vtkImagingSources;vtkFiltersHybrid;vtkFiltersHyperTree;vtkImagingGeneral;vtkFiltersImaging;vtkFiltersModeling;vtkFiltersParallel;vtkFiltersParallelImaging;vtkFiltersPoints;vtkFiltersProgrammable;/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/Python;vtkPythonInterpreter;vtkWrappingTools;vtkWrappingPythonCore;vtkFiltersPython;vtkFiltersSMP;vtkFiltersSelection;vtkFiltersTexture;vtkFiltersTopology;verdict;vtkFiltersVerdict;vtkInteractionStyle;vtkGUISupportQt;vtksqlite;vtkIOSQL;vtkGUISupportQtSQL;vtkmetaio;/usr/local/lib/libjpeg.dylib;/usr/local/lib/libpng.dylib;/usr/local/lib/libtiff.dylib;vtkIOImage;vtkImagingHybrid;vtkInfovisLayout;vtkImagingColor;vtkRenderingAnnotation;vtkRenderingVolume;vtkInteractionWidgets;vtkViewsCore;vtklibproj;vtkGeovisCore;/usr/local/lib/libhdf5.dylib;/usr/local/lib/libsz.dylib;/usr/lib/libdl.dylib;/usr/lib/libm.dylib;/usr/local/lib/libhdf5_hl.dylib;vtkIOAMR;vtkIOAsynchronous;vtkpugixml;vtkIOCityGML;vtkIOEnSight;/usr/local/lib/libnetcdf.dylib;vtkexodusII;vtkIOExodus;vtkgl2ps;vtkRenderingGL2PSOpenGL2;vtkIOExport;vtkIOExportOpenGL2;vtklibharu;vtkIOExportPDF;vtkIOGeometry;vtkIOImport;/usr/lib/libxml2.dylib;vtkIOInfovis;vtkIOLSDyna;vtkIOMINC;vtkogg;vtktheora;vtkIOMovie;vtkIONetCDF;vtkIOPLY;vtkjsoncpp;vtkIOParallel;vtkIOParallelXML;vtkIOSegY;vtkIOTecplotTable;vtkIOVeraOut;vtkIOVideo;vtkImagingMath;vtkImagingMorphological;vtkImagingStatistics;vtkImagingStencil;vtkInfovisBoostGraphAlgorithms;vtkInteractionImage;vtkPythonContext2D;vtkRenderingContextOpenGL2;vtkRenderingFreeTypeFontConfig;vtkRenderingImage;vtkRenderingLOD;vtkRenderingLabel;vtkRenderingQt;vtkRenderingVolumeOpenGL2;vtkViewsContext2D;vtkViewsInfovis;vtkViewsQt  
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/zhi/Desktop/PCLtest/cmake-build-debug

make后输出:

powershell 复制代码
Scanning dependencies of target PCLtest
[ 50%] Building CXX object CMakeFiles/PCLtest.dir/main.cpp.o
[100%] Linking CXX executable PCLtest
[100%] Built target PCLtest

编译成功后,运行工程:

php 复制代码
./pcd_write_test

运行结果:

php 复制代码
Saved 5 data points to test_pcd.pcd.
    0.0080142 0.694695 -0.26015
    -0.342265 -0.446349 0.214207
    0.173687 -0.84253 -0.400481
    -0.874475 0.706127 -0.117635
    0.908514 -0.598159 0.744714

使用CLion配置PCL

打开CLion新建工程,工程自动给出CMakeLists.txt和main.cpp,在对应文件中写入内容后运行即可

配置过程中出现的各种奇怪问题

  1. 在编译前检查是否安装cmake,若没有安装,直接brew install cmake即可
  2. 尽量使用gcc进行编译,若没有安装,直接brew install gcc(亲身验证,使用clang也可以。。。在编译过程中一直出现错误,病急乱投医,一度认为是编译器的问题)
  3. 由于mac默认c编译器为clang,如果想使用gcc编译,参考:CMake 指定gcc编译版本
powershell 复制代码
export CC=/usr/local/bin/gcc #你的gcc编译器路径
export CXX=/usr/local/bin/g++
cmake /path/to/your/project
make 
  1. 整个过程中最烦心的错误出现了,搜索全网都没有找到与我出现相同错误的同学!!此时cmake是成功的,但是在make时提示出现错误:
powershell 复制代码
Scanning dependencies of target pcd_write_test
[ 50%] Building CXX object CMakeFiles/pcd_write_test.dir/pcd_write.cpp.o
make[2]: *** No rule to make target `/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/Python', needed by `pcd_write_test'.  Stop.
make[1]: *** [CMakeFiles/pcd_write_test.dir/all] Error 2
make: *** [all] Error 2

解决方案(非常粗暴)找到文件夹/usr/local/Cellar/python/,发现里面只有一个文件夹3.7.4,直接将其文件夹名称改为3.7.3,问题解决

相关推荐
Ajiang28247353041 小时前
对于C++中stack和queue的认识以及priority_queue的模拟实现
开发语言·c++
‘’林花谢了春红‘’6 小时前
C++ list (链表)容器
c++·链表·list
小江村儿的文杰7 小时前
XCode Build时遇到 .entitlements could not be opened 的问题
ide·macos·ue4·xcode
机器视觉知识推荐、就业指导7 小时前
C++设计模式:建造者模式(Builder) 房屋建造案例
c++
Yang.999 小时前
基于Windows系统用C++做一个点名工具
c++·windows·sql·visual studio code·sqlite3
熬夜学编程的小王9 小时前
【初阶数据结构篇】双向链表的实现(赋源码)
数据结构·c++·链表·双向链表
zz40_10 小时前
C++自己写类 和 运算符重载函数
c++
天涯倦客的美丽人生10 小时前
2024年11月最新 Alfred 5 Powerpack (MACOS)下载
macos
六月的翅膀10 小时前
C++:实例访问静态成员函数和类访问静态成员函数有什么区别
开发语言·c++