本文记录ubuntu下安装opencv过程,步骤来自 opencv官网可以对照官网步骤:
https://docs.opencv.org/3.4.0/d7/d9f/tutorial\_linux\_install.html
(1)、Required Packages(安装必要的库,以及想要的功能的库,使用cmake ..时会检查哪些依赖库安装了,然后就会开启哪些功能对应的写入到Makefile文件中,如果有些需要的库没有安装,那么对应的功能就不能使用):
GCC 4.4.x or later
CMake 2.8.7 or higher
Git
GTK+2.x or higher, including headers (libgtk2.0-dev)
pkg-config
Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
[optional] libtbb2 libtbb-dev
[optional] libdc1394 2.x
[optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
[optional] CUDA Toolkit 6.5 or higher
The packages can be installed using a terminal and the following commands or by using Synaptic Manager:
[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
下面是具体的安装命令(如果下面那些东西之前已经安装过那么就没有必要安装了,比如我的cmake git 之前都安装好了,所以我在第二条命令就去掉了cmake git ):
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
slam需要的库(可参考视觉slam十四讲95页内容),下面的库会与上面安装过的库有重复,你可以对照着上面跳过重复的库(实际上 libvtk5-dev libtiff4-dev(这个安装过程会有问题,下面会有说明) libopenexr-dev是不重复的,下面列举出全部的原因,是为了明确slam需要的库):
sudo apt-get install build-essential libgtk2.0-dev libvtk5-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev libtbb-dev
(插入说明:在安装上面的依赖库时,仅仅libtiff4-dev出现了错误(这个库是用来支持TIFF图像的),会有提示信息,可以按照提示替换为libtiff5-dev。当然如果提示了更高的版本,就对应安装提示的库。)
(2)、Getting OpenCV Source Code(获得Opencv源码)
可以到下面的网址下载源码包:https://opencv.org/releases.html
(3)、Building OpenCV from Source Using CMake(使用CMake编译安装源码)
打开源码包,之后在该路径下打开终端。输入如下指令:
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j4 # runs 4 jobs in parallel(4线程同时安装 速度比单线程快)
sudo make install
说明:
-D CMAKE_INSTALL_PREFIX=/usr/local .. 这个选项表示你将Opencv库安装的目录。可以选择其他目录。这个目录里面会找到包含lib库 和头文件库的文件夹。
参考资料;
1、https://docs.opencv.org/3.4.0/d7/d9f/tutorial\_linux\_install.html
2、https://docs.opencv.org/2.4/doc/tutorials/introduction/linux\_install/linux\_install.html?highlight=install
3、Opecv常用模块的说明:https://docs.opencv.org/3.4.0/d9/df8/tutorial\_root.html