Ubuntu18.04 安装Opencv3.4.16、PCL1.8.0、VTK7.1.0、Eigen3.4、Pangolin0.6、Sophus、Ceres-solver、g2o
刚配好Ubuntu18.04双系统建议安装顺序:
Eigen3.4.0--> VTK7.1.0--> PCL1.8.0--> Opencv3.4.16、Opencv-contrib3.4.15-->
Ceres-solve--> Sophus--> Pangolin0.6--> g2o
Eigen3.4
安装方法
mkdir build && cd build
cmake ..
sudo make install
安装后头文件安装在/usr/local/include/eigen3/, 可以打开看一看
Pangolin0.6
安装方法
安装依赖项目
sudo apt-get install libglew-dev
sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev
sudo apt-get install libpython2.7-dev
mkdir build && cd build
cmake ..
make -j
sudo make install
Sophus
安装方法
mkdir build && cd build
cmake ..
make -j
sudo make install
Ceres-solver
-
安装方法
g2o
安装方法
-
先安装依赖包
-
sudo apt-get install libsuitesparse-dev qtdeclarative5-dev qt5-qmake libqglviewer-dev-qt5
-
然后才开始安装
-
mkdir build && cd build cmake .. make -j sudo make install
OpenCV
- 安装方法
(1)安装依赖项:
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libatlas-base-dev gfortran libgtk2.0-dev libjpeg-dev libpng-dev
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev liblapacke-dev checkinstall
问题解决:“E: 无法定位软件包 libjasper-dev“
打开软件源配置文件进行编辑
sudo gedit /etc/apt/sources.list
首行增加
deb http://security.ubuntu.com/ubuntu xenial-security main
更新软件源
sudo apt-get update
(2) 然后才开始安装
进入opencv-3.4.16文件夹,打开终端,输入:
mkdir build
cd build
接下来编译安装,注意此命令的OPENCV_EXTRA_MODULES_PATH=后边的路径是你电脑下的绝对路径,请自行修改
```cmake
# 进入下载的安装压缩包,解压到某文件夹,然后进去该文件夹建立build文件夹 编译文件夹
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_GTK_2_X=ON -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_GENERATE_PKGCONFIG=YES -D OPENCV_EXTRA_MODULES_PATH=/home/lx/fromUbuntu18/thirdParty/opencv-3.4.16/opencv_contrib-3.4.16/modules -D WITH_CUDA=ON -D WITH_CUDNN=ON -D WITH_FFMPEG=ON -D WITH_OPENGL=ON -D WITH_NVCUVID=ON -D -DENABLE_PRECOMPILED_HEADERS=OFF -D CMAKE_EXE_LINKER_FLAGS=-lcblas -DWITH_LAPACK=OFF -j6 ..
sudo make -j12
sudo make install
到此安装Opencv的以上过程也可参考该博客
(3)配置环境变量
sudo vim /etc/ld.so.conf.d/opencv.conf
# 在打开的空白文件中添加 /usr/local/lib
执行sudo ldconfig,使配置的环境变量生效
(4)配置.bashrc,末尾添加下面两行
# 打开.bashrc
sudo vim /etc/bash.bashrc
# 添加以下两行内容到.bashrc
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
(5)source 与 update
source /etc/bash.bashrc
sudo updatedb
多版本Opencv及其Opencv-contrib安装
参考博客1
参考博客2
多版本安装过程和安装单一版本一样,只不过从安装第二个版本开始就不能按照默认路径进行安装需要自己手动进行设置即需要在make时指定安装路径,在之前cmake后加入此参数 -D CMAKE_INSTALL_PREFIX=/usr/local/opencv4:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_GTK_2_X=ON -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_GENERATE_PKGCONFIG=YES -D OPENCV_EXTRA_MODULES_PATH=/home/lx/fromUbuntu18/thirdParty/opencv-4.5.4/opencv_contrib-4.5.4/modules -D WITH_CUDA=ON -D WITH_CUDNN=ON -D WITH_FFMPEG=ON -D WITH_OPENGL=ON -D WITH_NVCUVID=ON -D -DENABLE_PRECOMPILED_HEADERS=OFF -D CMAKE_EXE_LINKER_FLAGS=-lcblas -DWITH_LAPACK=OFF -j6 -D CMAKE_INSTALL_PREFIX=/usr/local/opencv4 ..
当需要在项目中使用别的版本Opencv进行编译项目时,需要在CMakeLists.txt中手动指定版本号:
set(OpenCV_DIR "/home/lx/fromUbuntu18/thirdParty/opencv-4.5.4/build")
find_package(OpenCV REQUIRED)
PCL1.8.0、 VTK7.1.0
注意要先安装VTK再安装PCL
第一步:安装各种依赖
sudo apt-get update
sudo apt-get install git build-essential linux-libc-dev
sudo apt-get install cmake cmake-gui
sudo apt-get install libusb-1.0-0-dev libusb-dev libudev-dev
sudo apt-get install mpi-default-dev openmpi-bin openmpi-common
sudo apt-get install libflann1.9 libflann-dev (ubuntu18对应1。9,ubuntu16对应1。8)
sudo apt-get install libeigen3-dev
sudo apt-get install libboost-all-dev
sudo apt-get install libqhull* libgtest-dev
sudo apt-get install freeglut3-dev pkg-config
sudo apt-get install libxmu-dev libxi-dev
sudo apt-get install mono-complete
sudo apt-get install libopenni-dev
sudo apt-get install libopenni2-dev
sudo apt-get install libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev
sudo apt-get install build-essential libgl1-mesa-dev libglu1-mesa-dev
第二步安装VTK7.1
wget http://www.vtk.org/files/release/7.1/VTK-7.1.0.tar.gz
tar -zxvf VTK-7.1.0.tar.gz
cd VTK-7.1.0 && mkdir build && cd build
cmake ..
make -j
sudo make install
第三步安装PCL1.8.0
安装PCL参考这个
PCL安装出错参考这个
出错简要记录:
错误1:
error: invalid initialization of reference of type ‘const std::vector<float>&’ from expression of type ‘const boost::shared_ptr<std::vector<float> >’
144 | return (plane_coeff_d_);
在plane_coefficient_comparator.h中的第144行return (plane_coeff_d_)修改为return (* plane_coeff_d_);
PCL1.8.0安装后的测试样例:
创建一个文件夹,在里面创建pcltest.cpp、CMakeLists.txt,以下为pcltest.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;
}
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 pcltest.cpp)
target_link_libraries (pcl_test ${PCL_LIBRARIES})
之后在此文件夹下打开命令行输入:
cmake .
make -j2
./pcl_test
滚动鼠标滚轮并拖拽出现如下效果时说明PCL1.8.0安装成功:
运行过程中如果遇到如下问题:
error while loading shared libraries: libvtkglew-7.1.so.1: cannot open shared object file: No such file or directory
解决办法如下:
1) 打开/etc/ld.so.conf文件;
2) 接着在后面增加"/usr/local/lib"并保存退出;
3) 最后在终端执行ldconfig,使所有的库文件都被缓存到文件/etc/ld.so.conf中以供程序运行时调用
完成以上三步即可解决问题。
在机子上有gcc7的话,切换gcc到gcc7
rm -rf `which gcc`
rm -rf `which g++`
rm -rf `which gfortran`
ln -s `which gcc-7` /usr/bin/gcc
ln -s `which g++-7` /usr/bin/g++
ln -s `which gfortran-7` /usr/bin/gfortran
不要手动输入,直接复制到命令行执行。