ubuntu20.04安装pcl

1.先安装各种依赖

sudo apt-get update
sudo apt-get install git build-essential linux-libc-dev
sudo apt-get install cmake cmake-gui
sudo apt-get install libusb-1.0-0-dev libusb-dev libudev-dev
sudo apt-get install mpi-default-dev openmpi-bin openmpi-common
sudo apt-get install libflann1.8 libflann-dev
sudo apt-get install libeigen3-dev
sudo apt-get install libboost-all-dev

其他依赖

sudo apt-get install libqhull* libgtest-dev  
sudo apt-get install freeglut3-dev pkg-config  
sudo apt-get install libxmu-dev libxi-dev   
sudo apt-get install mono-complete   
sudo apt-get install libopenni-dev   
sudo apt-get install libopenni2-dev 

2.源码安装vtk库

(很重要!!!apt安装的方式会出现.so文件缺失的情况!)

2.1首先安装依赖项X11,OpenGL,CMake-gui

  • x11
sudo apt-get install libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev
  • OpenGL
sudo apt-get install build-essential libgl1-mesa-dev libglu1-mesa-dev
  • cmake
sudo apt-get install cmake cmake-gui 

2.2下载vtk源码

我选择了VTK-9.1.1.tar.gz,下载完成后解压缩到你的文件安装目录。在文件目录下打开cmd窗口,输入cmake-gui打开cmake图形界面:

配置“where is the source code”的路径为vtk-7.1.1所在的目录

在vtk-7.1.1目录新建build文件夹,配置“where to build the binaries”为build文件夹

点击Configure,配置完成后提示configure done

选择“VTK_GROUP_QT”再次点击configure

配置完成后点击generate按钮,会在build文件夹下生成工程文件

2.3 切换文件目录到vtk-7.1.1文件夹下的build文件夹,然后打开cmd窗口,输入:

make -j8
sudo make install

完成vtk库的安装.

3.安装pcl

去pcl官方github下载需要的pcl版本放到主目录下
然后:

cd pcl 
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=None ..
make (如果速度太慢用 make -j8 ;默认使用单核make,-j8启用8核)
sudo make install

-j8 参考

4.pcl 测试

执行c++代码必须编译工程,就需要用到CMakeLists.txt;

把pcl_test.cpp和CMakeLists.txt放在同一个文件夹里,并创建build文件夹,如下图
ubuntu20.04安装pcl_第1张图片

测试代码pcl_test.cpp内容如下:

#include 
#include 
#include 
#include 
#include 
#include 
 
 
int main(int argc, char **argv) {
    std::cout << "Test PCL !!!" << std::endl;
    
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>);
    uint8_t r(255), g(15), b(15);
    for (float z(-1.0); z <= 1.0; z += 0.05)
    {
      for (float angle(0.0); angle <= 360.0; angle += 5.0)
      {
	pcl::PointXYZRGB point;
	point.x = 0.5 * cosf (pcl::deg2rad(angle));
	point.y = sinf (pcl::deg2rad(angle));
	point.z = z;
	uint32_t rgb = (static_cast<uint32_t>(r) << 16 |
		static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b));
	point.rgb = *reinterpret_cast<float*>(&rgb);
	point_cloud_ptr->points.push_back (point);
      }
      if (z < 0.0)
      {
	r -= 12;
	g += 12;
      }
      else
      {
	g -= 12;
	b += 12;
      }
    }
    point_cloud_ptr->width = (int) point_cloud_ptr->points.size ();
    point_cloud_ptr->height = 1;
    
    pcl::visualization::CloudViewer viewer ("test");
    viewer.showCloud(point_cloud_ptr);
    while (!viewer.wasStopped()){ };
    return 0;
}

CMakeLists.txt文件内容如下:(直接输入以下代码)

cmake_minimum_required(VERSION 2.6)
project(pcl_test)

find_package(PCL 1.2 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable(pcl_test pcl_test.cpp)

target_link_libraries (pcl_test ${PCL_LIBRARIES})

install(TARGETS pcl_test RUNTIME DESTINATION bin)

执行如下命令:

cd build
cmake ..
make
./pcl_test

就可以看到一个漂亮的3D模型

你可能感兴趣的:(pcl,c++,cmake)