《点云库PCL从入门到精通》程序在Linux Ubuntu上运行

  • 《点云库PCL从入门到精通》这本书中,虽然在第二章介绍了在 windows 和 linux 上的安装方法,但是书里面的程序都是在 windows 上运行的,所以写一下如何在 linux 中运行书中程序,书中程序 github 下载地址:链接
  • 系统:Ubuntu 16.04,PCL 1.8.1
  • 以第二章例1的程序为例,另外书中的滤波测试程序好像有点问题,我在本文最后附上了我所使用的 testfilter.cpp 和相应的 CMakeLists.txt 文件(也就是在 src 里面的两个文件)
  1. 如下图所示,程序中的文件夹命名为 source,先将其改名为 src
    在这里插入图片描述
  2. 然后在此文件夹下打开终端,并在终端中输入:catkin_make,会生成 build 和 devel 文件夹
    在这里插入图片描述
  3. 编译完之后如下图,可以看到在 build 文件夹中创建了 testfilter 可执行文件
    在这里插入图片描述
    在这里插入图片描述
  4. 然后还是在 src 所在文件夹,输入:./build/testfilter,这一步就是执行生成的可执行文件,如下图
    在这里插入图片描述
  5. 注意:如果执行的 .cpp 文件中有需要导入的文件,那么需要将文件复制到与 src 同一文件夹,例如第10章例1,这样就不需要修改路径了,否则还需要在 cpp 文件的导入语句中加上文件路径。
    在这里插入图片描述

testfilter.cpp

#include <iostream>  
#include <pcl/io/pcd_io.h>  
#include <pcl/point_types.h>  
#include <pcl/ModelCoefficients.h>  
#include <pcl/filters/project_inliers.h>  
  
int main(int argc, char** argv)  
{  
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);  
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_projected(new pcl::PointCloud<pcl::PointXYZ>);  
  
    // Fill in the cloud data  
    cloud->width = 5;  
    cloud->height = 1;  
    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);  
    }  
  
    std::cerr << "Cloud before projection: " << 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;  
  
    // Create a set of planar coefficients with X=Y=0,Z=1  
    pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients());  
    coefficients->values.resize(4);  
    coefficients->values[0] = coefficients->values[1] = 0;  
    coefficients->values[2] = 1.0;  
    coefficients->values[3] = 0;  
  
    // Create the filtering object  
    pcl::ProjectInliers<pcl::PointXYZ> proj;  
    proj.setModelType(pcl::SACMODEL_PLANE);  
    proj.setInputCloud(cloud);  
    proj.setModelCoefficients(coefficients);  
    proj.filter(*cloud_projected);  
  
    std::cerr << "Cloud after projection: " << std::endl;  
    for (size_t i = 0; i < cloud_projected->points.size(); ++i)  
        std::cerr << "    " << cloud_projected->points[i].x << " "  
        << cloud_projected->points[i].y << " "  
        << cloud_projected->points[i].z << std::endl;  
  
    system("pause");  
    return (0);  
}  

CMakeLists.txt

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(testfilter)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (testfilter testfilter.cpp)
target_link_libraries (testfilter ${PCL_LIBRARIES})
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值