Ubuntu16.04安装PCL1.8(源码编译),代码测试

第一步:安装依赖

     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

对于update出现 GPG 错误:: 由于没有公钥,无法验证下列签名: NO_PUBKEY F42ED6FBAB17C654 的问题移步https://blog.csdn.net/suyunzzz/article/details/96717770

第二步:下载源码

git clone https://github.com/PointCloudLibrary/pcl.git

在我下载时速度非常慢,如下,不知道为啥。

收对象中:  12% (15741/123507), 7.28 MiB | 9.00 KiB/s

解决:

使用码云进行git clone。具体见https://blog.csdn.net/xy_zhangchn/article/details/81558144,效果如下,

接收对象中: 100% (123507/123507), 221.96 MiB | 4.51 MiB/s, 完成.

第三步:编译源码

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

这里貌似会出现一个错误,没有可视化模块,其实在cmake完成以后就能查看有没有这个模块 。原因是因为vtk的问题,可能在安装pcl之前vtk版本不满足或者忘记安装了,如果出现这个情况,应该删掉所有的pcl相关的,重新编译。

     sudo make install

第四步(可选 and 建议):如果需要PCLVisualizer 安装OpenNI、OpenNI2

sudo apt-get install libopenni-dev 
sudo apt-get install libopenni2-dev

Done.

---------------------------------------------------------------------------------------------------------------------------------------------------

测试

参考https://blog.csdn.net/huoxingrenhdh/article/details/83780506

mkdir pcl_test
cd pcl_test
vim pcl_test.cpp

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;
}
vim CMakeLists.txt

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)

然后在pcl_test文件夹下新建一个build文件夹:

mkdir build && cd build
cmake ..                      ##cmake ..代表对上级目录内的CMakeLists进行生成编译文件
make                          ##根据生成的编译文件进行编译
./pcl_test                    ##执行生成的可执行文件

结果如下:

Ubuntu16.04安装PCL1.8(源码编译),代码测试_第1张图片

你可能感兴趣的:(PointCloud,C/C++,cmake)