[pcl][转载]pcl在ubuntu上安装后测试代码

Posted FL1623863129

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[pcl][转载]pcl在ubuntu上安装后测试代码相关的知识,希望对你有一定的参考价值。

CMalkeList.txt

cmake_minimum_required(VERSION 2.6)
project(test_pcl)

find_package(PCL 1.11.1 REQUIRED)

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

add_executable(test_pcl test_pcl.cpp)

target_link_libraries (test_pcl ${PCL_LIBRARIES})

install(TARGETS test_pcl RUNTIME DESTINATION bin)

test_pcl.cpp

#include <iostream>
#include <pcl/common/common_headers.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/console/parse.h>

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;
}

以上是关于[pcl][转载]pcl在ubuntu上安装后测试代码的主要内容,如果未能解决你的问题,请参考以下文章

[ubuntu][转载]pcl安装依赖

[C++][PCL]pcl在windows上安装后测试代码2

[C++][PCL]pcl在windows上安装后测试代码2

Ubuntu18.04安装PCL 1.9.1(图文详解,附踩坑和测试)

Ubuntu 16.04 安装PCL库以及测试

Ubuntu 配置安装PCL