适用系统:Ubuntu 16.04 、 Ubuntu18.04
Cpu架构:X86、Arm
OpenCV版本:OpenCV-3.4.1
VTK版本:VTK-7.1.1
PCL版本:PCL-1.8.1
源码包打包下载:
OpenCV-3.4.1+VTK-7.1.1+PCL-1.8.1源码包
目录
第一步:更改Ubuntu软件源,这样下载和更新依赖会更快
第二步:安装cmake
第三步:编译安装OpenCV-3.4.1
第四步:编译安装VTK-7.1.1(特别注意:PCL是依赖VTK的,所以,必须先编译安装VTK!!)
第五步:编译安装PCL-1.8.1
第六步:添加环境变量(防止后面程序使用依赖库的时候找不到依赖库!!!)
1.备份Ubuntu软件源配置文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
2、修改sources.list文件(修改为华为的源)
如果你电脑是X86架构,就复制下面的源覆盖sources.list的源
deb http://repo.huaweicloud.com/ubuntu/ bionic main restricted
deb http://repo.huaweicloud.com/ubuntu/ bionic-updates main restricted
deb http://repo.huaweicloud.com/ubuntu/ bionic universe
deb http://repo.huaweicloud.com/ubuntu/ bionic-updates universe
deb http://repo.huaweicloud.com/ubuntu/ bionic multiverse
deb http://repo.huaweicloud.com/ubuntu/ bionic-updates multiverse
deb http://repo.huaweicloud.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://repo.huaweicloud.com/ubuntu bionic-security main restricted
deb http://repo.huaweicloud.com/ubuntu bionic-security universe
deb http://repo.huaweicloud.com/ubuntu bionic-security multiverse
如果你电脑是ARM架构,就复制下面的源覆盖sources.list的源
deb https://repo.huaweicloud.com/ubuntu-ports/ bionic main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic main restricted universe multiverse
deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-security main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-security main restricted universe multiverse
deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
## Not recommended
# deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-proposed main restricted universe multiverse
# deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-proposed main restricted universe multiverse
3、执行apt-get update更新索引
sudo apt-get update
4.执行sudo apt-get upgrade更新软件
sudo apt-get upgrade
sudo apt-get install cmake
sudo apt-get upgrade
检查cmake是否安装成功
cmake --version
1.安装OpenCV-3.4.1 依赖文件 的 依赖文件(否则后面会报: errorE: unable to locate libjasper-dev errorE: unable to locate libjasper-dev)
对于 x86 工控机:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
对于 arm 工控机:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
2.安装OpenCV-3.4.1 依赖文件
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev
3.进入解压后的opencv源码包文件夹,创建编译文件夹,cmake一下生成Makefile文件
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE WITH_CUDA=OFF ..
4.cmake 生成Makefile后,执行make命令,漫长的编译过程..........!
sudo make -j4
5.编译成功后,安装OpenCV
sudo make install
6.安装OpenCV执行完毕后,接下来就需要配置一些OpenCV的编译环境,首先将OpenCV的库添加到路径,从而可以让系统找到
sudo gedit /etc/ld.so.conf.d/opencv.conf
执行此命令后打开的可能是一个空白的文件,不用管它,只需要在文件末尾添加
/usr/local/lib
执行保存文件后,要运行如下命令使得刚才的配置路径生效
sudo ldconfig
7.添加OpenCV环境变量到.bashrc文件
sudo gedit /etc/bash.bashrc
在最末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
保存,执行如下命令使得配置文件生效
source /etc/bash.bashrc
8.创更新slocate命令所必需的数据库文件(系统中文件与目录的相关信息)
sudo updatedb
至此OpenCV所有的配置都已经完成!!!
备注: 如果报错:sudo: updatedb: command not found
解决方法:sudo apt-get install mlocate
然后重新执行 sudo updatedb
1.先安装各种依赖,其中也包含有PCL的依赖(注意!!第6条命令:ubuntu 16.04 为 libflann1.8 ,ubuntu 18.04 为 libflann1.9)切记!!最好一条一条复制执行,不要全复制粘贴执行!!!!!!
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
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
2.编译源码安装vtk库(很重要!!!apt安装的方式会出现.so文件缺失的情况!!!)
解压vtk源码安装包,进去解压后的文件夹,打开终端,创建build文件夹进入build文件夹cmake生成Makefile文件。
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE ..
3.编译源码(比较漫长.......)
sudo make -j4
4.安装编译好的VTK依赖库
sudo make install
VTK安装完成!!!
1.安装依赖库
sudo apt-get install pcl-tools libpcl-dev libjpeg-turbo8-dev
3.编译安装PCL-1.8.1
解压pcl源码包,进去解压文件夹打开终端,创建build文件夹并进入build文件夹cmake生成makefile文件。
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=RELEASE ..
4.编译PCL-1.8.1
sudo make -j4
5.安装编译好的PCL-1.8.1
sudo make install
PCL安装完成!!!
打开profile文件:
sudo gedit /etc/profile
在文件末尾添加下面2条文本:
export PATH=/usr/local/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
添加后保存文件,并执行如下命令使得配置文件生效
source /etc/profile
执行保存文件后,要运行如下命令使得刚才的配置路径生效
sudo ldconfig