Ubuntu18.04成功配置pcl1.8

由于科研需要用到pcl库,网上的教程各种各样,大多建议自己编译安装,我曾经试过一次,崩到哪里都不知道了,还把系统重装了一次,所以这次我就直接采用了官网的方式安装。

我的系统是Ubuntu18.04,所以下面的方法不保证所有的系统通用。

1、先命令行输入下面三行

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

没错,就是这三行,如果安装顺利的话,这三行运行结束你就可以直接跑点云,免去一系列繁琐的配置。

2、遇到的问题
Ubuntu18.04成功配置pcl1.8_第1张图片
遇到上面这种情况,不用慌,按enter继续就是了。

3、安装成功
Ubuntu18.04成功配置pcl1.8_第2张图片
没几分钟我这就全部安装结束了,我以为还要像那些教程里说的,还要cmake,make啥的,事实上如果进入到pcl安装文件夹,根本没有CMakeLists.txt文件,也就是说这种方式安装的话到这里已经全部结束了。

4、测试,新建一个文件夹,写一个测试文件和CMakeLists.txt,如下

#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/videoio.hpp"
#include 

using namespace cv;
using namespace std;

void drawText(Mat & image);

int main()
{
    cout << "Built with OpenCV " << CV_VERSION << endl;
    Mat image;
    VideoCapture capture;
    capture.open(0);
    if(capture.isOpened())
    {
        cout << "Capture is opened" << endl;
        for(;;)
        {
            capture >> image;
            if(image.empty())
                break;
            drawText(image);
            imshow("Sample", image);
            if(waitKey(10) >= 0)
                break;
        }
    }
    else
    {
        cout << "No capture" << endl;
        image = Mat::zeros(480, 640, CV_8UC1);
        drawText(image);
        imshow("Sample", image);
        waitKey(0);
    }
    return 0;
}

void drawText(Mat & image)
{
    putText(image, "Hello OpenCV",
            Point(20, 50),
            FONT_HERSHEY_COMPLEX, 1, // font face and scale
            Scalar(255, 255, 255), // white
            1, LINE_AA); // line thickness and type
}

下面是CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

project(pcl_test)

# 注意版本要与安装的一样
find_package(PCL 1.8 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})

link_directories(${PCL_LIBRARY_DIRS})

add_definitions(${PCL_DEFINITIONS})

add_executable(pcl_test test.cpp)

target_link_libraries (pcl_test ${PCL_LIBRARIES})

install(TARGETS pcl_test RUNTIME DESTINATION bin)

然后就是熟悉的新建build文件夹,在里面进行cmake和make

mkdir build
cd build
cmake ..
make

中间可能会报一个警告,说auto_ptr已经弃用了,我们不用管这些,最后还是成功编译了
Ubuntu18.04成功配置pcl1.8_第3张图片
完美运行

./pcl_test

Ubuntu18.04成功配置pcl1.8_第4张图片



总结
建议用官网推荐的这种方式安装pcl,这种方式崩的可能性比自己下载一大堆库再编译的方法绝对要小

你可能感兴趣的:(笔记)