Ubuntu16.04编译安装PCL&测试运行

环境:ubuntu16.04
pcl版本:1.8.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 libvtk5.10-qt4 libvtk5.10 libvtk5-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 qt-sdk openjdk-8-jdk openjdk-8-jre  

二.下载解压PCL
我是直接从https://github.com/PointCloudLibrary/pcl/releases下载的pcl-pcl-1.8.1.tar.gz。
解压后进入目录,用Cmake编译

mkdir build  
cd build  
cmake -DCMAKE_BUILD_TYPE=None -DCMAKE_INSTALL_PREFIX=/usr \  
      -DBUILD_GPU=ON -DBUILD_apps=ON -DBUILD_examples=ON \  
      -DCMAKE_INSTALL_PREFIX=/usr ..  

make 
sudo make install 

过程比较久,慢慢等
三.测试点云显示
测试代码pcl_test.cpp:

#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<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})  
    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) 

将两个文件放在同一目录下,编译

cmake .  
make  
./pcl_test 

编译成功后,运行能够看到一个3D模型

Ubuntu16.04编译安装PCL&测试运行_第1张图片
四.遇到的问题

make的时候遇到:No rule to make target ‘/usr/lib/x86_64-linux-gnu/libproj.so
解决方法:
sudo apt-get install libproj-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/libproj.so.9 /usr/lib/x86_64-linux-gnu/libproj.so

make时遇到:cannot find -lvtkproj4
解决办法:
在cmakelist中加一条指令修复,即在add_executable语句前面加上list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")

你可能感兴趣的:(图像处理)