UBUNTU16.04命令行安装PCL1.7(亲测有效)

安装PCL点云库,最开始是按照先安装相关依赖,然后github上clone PCL相关版本包的形式安装的,编译遇到了很多问题,结果最后安装完成,但却无法运行例程。难过。。。

又尝试了命令行的形式,命令行的形式直观简单,可安装编译好的点云库(PCL-1.7),附带安装了VTK-6.2.0等依赖库。

命令行安装最好保证网络情况,因为网络不好可能会出现下载失败等情况。

具体步骤如下:

1.PCL安装

sudo apt-get install libpcl-dev pcl-tools libproj-dev

装后的编译过程可能会出现库文件vtkproj4.so丢失的问题。为解决该问题可以直接软链接解决:

sudo ln -s /usr/lib/libvtkproj4.so.5.10 /usr/lib/libvtkproj4.so

2.pcl-viewer的安装

sudo apt-get install  pcl-tools

3.测试

新建一个文件pcl_test,然后在该文件夹中放入pcl_test.cpp和CMakeLists.txt文件,如下:

(1)pcl_test.cpp

#include 
#include 
#include 
#include 
#include 
#include 
 
 
int main(int argc, char **argv) {
    std::cout << "Test PCL !!!" << std::endl;
    
    pcl::PointCloud::Ptr point_cloud_ptr (new pcl::PointCloud);
    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(r) << 16 |
		static_cast(g) << 8 | static_cast(b));
	point.rgb = *reinterpret_cast(&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;
}

(2)CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(pcl_test)
 
find_package(PCL 1.7 REQUIRED)
 
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
 
#list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")
add_executable(pcl_test pcl_test.cpp)
 
target_link_libraries (pcl_test ${PCL_LIBRARIES})
 
install(TARGETS pcl_test RUNTIME DESTINATION bin)

然后再在该文夹下打开终端:

mkdir build
cd build
cmake ..
make

编译成功的话会在build中生成pcl_test的可执行文件,然后:

./pcl_test

结果:

UBUNTU16.04命令行安装PCL1.7(亲测有效)_第1张图片

 

 

参考文献:

https://blog.csdn.net/qq_43145072/article/details/85953948?utm_medium=distribute.pc_relevant_right.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param_right&depth_1-utm_source=distribute.pc_relevant_right.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param_right

https://blog.csdn.net/HHT0506/article/details/104439748

你可能感兴趣的:(pcl)