Ubuntu14.04 和Ubuntu16.04下安装PCL及测试

1.安装

1.1 Ubuntu 14.04

sudo add-apt-repository ppa:v-launchpad-jochen-sprickerhof-de/pcl
sudo apt-get update
sudo apt-get install libpcl-all

1.2 Ubuntu 16.04

sudo apt-get install libpcl-dev pcl-tools

2. 测试程序

新建pcltest文件夹,添加pcl_test.cpp和CMakeLists.txt两个文件:
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;
}

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)

然后在pcltest目录下:

cmake .
make
./pcl_test

3.最终效果

Ubuntu14.04 和Ubuntu16.04下安装PCL及测试_第1张图片

你可能感兴趣的:(Ubuntu)