PCL环境测试程序

虽然之前装好了环境,也测试过了。但是记性真的差,没几个礼拜没搞就忘了……

重新创建了一个文件夹(PCL_Learning)专门用于学习pcl了,现在写第一个程序,创建了一个工程(Test_environment),开始吧。注:Linux

KDevelop创建工程时会自动生成CMakeLists.txt文件。我们需要在里面添加pcl的内容。

1、修改CMakeLists文件

CMakeLists.txt内容如下:

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(test_environment)
find_package(PCL 1.8 REQUIRED COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(test_environment main.cpp)
target_link_libraries(test_environment ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES})
install(TARGETS test_environment RUNTIME DESTINATION bin)

完成后需要编译,编译完成后继续主程序的编写。

2、main.cpp

程序来自于官方例子:http://pointclouds.org/documentation/tutorials/using_pcl_pcl_config.php#using-pcl-pcl-config

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

int
  main (int argc, char** argv)
{
  pcl::PointCloud<pcl::PointXYZ> cloud;

  // Fill in the cloud data
  cloud.width    = 5;
  cloud.height   = 1;
  cloud.is_dense = false;
  cloud.points.resize (cloud.width * cloud.height);

  for (size_t i = 0; i < cloud.points.size (); ++i)
  {
    cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
  }

  pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
  std::cerr << "Saved " << cloud.points.size () << " data points to test_pcd.pcd." << std::endl;

  for (size_t i = 0; i < cloud.points.size (); ++i)
    std::cerr << "    " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;

  return (0);
}

最后main.cpp build->execute
测试结果如下:

Saved 5 data points to test_pcd.pcd.
    0.352222 -0.151883 -0.106395
    -0.397406 -0.473106 0.292602
    -0.731898 0.667105 0.441304
    -0.734766 0.854581 -0.0361733
    -0.4607 -0.277468 -0.916762

回顾结束,继续看书学。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值