适合小白:PCL第一个项目搭建

“Using PCL in your own project”

官方来源:Using PCL in your own project — Point Cloud Library 0.0 documentation

B站学习来源:00-PCL教程-Basic Usage-Using PCL in your own project_哔哩哔哩_bilibili

跟着视频实操步骤:

1.安装PCL

可以从中参考:(我使用ubuntu20.04 ,安装的1.10.0版本)

PCL(Point Cloud Library)学习指南&资料推荐 · 语雀

【Ubuntu】Ubuntu安装PCL(安装PCL/卸载PCL/查看PCL版本/PCL报错处理相关操作)(史上最详细)-CSDN博客

2.开始项目

2.1新建一个文件夹using_PCL

1.在新文件夹using_PCL下新建文件pcd_write.cpp

终端指令:

gedit pcd_write.cpp

把代码输入并保存。

#include <iostream>

#include <pcl/io/pcd_io.h>

#include <pcl/point_types.h>


int

  main ()

{

  pcl::PointCloud<pcl::PointXYZ> cloud;


  // Fill in the cloud data

  cloud.width    = 5;

  cloud.height   = 1;

  cloud.is_dense = false;

  cloud.resize (cloud.width * cloud.height);


  for (auto& point: cloud)

  {

    point.x = 1024 * rand () / (RAND_MAX + 1.0f);

    point.y = 1024 * rand () / (RAND_MAX + 1.0f);

    point.z = 1024 * rand () / (RAND_MAX + 1.0f);

  }


  pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);

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


  for (const auto& point: cloud)

    std::cerr << "    " << point.x << " " << point.y << " " << point.z << std::endl;


  return (0);

}

2.在using_PCL下新建文件CMakeLists.txt

gedit CMakeLists.txt

代码输入并保存:

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(MY_GRAND_PROJECT)
find_package(PCL 1.3 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(pcd_write_test pcd_write.cpp)
target_link_libraries(pcd_write_test ${PCL_LIBRARIES})

3.开始编译

在using_PCL文件夹下,打开终端 :

mkdir build
cd build
cmake ..
make

3.项目结果

3.1运行项目

3.1.1代码

./pcd_write_test
pcl_viewer test_pcd.pcd

3.1.2结果

结果是五个点,可能不太清楚

-end-

  • 19
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值