官网手册中的说明基本上是比较全的,这里主要记录下安装过程,以及编译选项 多看官方手册,少走弯路 官网安装说明:https://docs.opencv.org/3.4.0/d7/d9f/tutorial_linux_install.htmlhtml
环境: Ubuntu 16.04 64bit ,openCV 3.4.0
1、安装opencv依赖包
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:python
[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-devlinux
2、安装numpy(若是须要python使用)
这里用的使用python3,因此是pip3命令,若是用python2,直接改成pip命令便可git
pip3 install numpygithub
3、下载opencv3.4.0
须要下载opencv和opencv_contrib(后者会在cmake配置的时候用到),这是由于opencv3之后SIFT和SURF之类的属性被移到了contrib中 下载地址:bootstrap
https://opencv.org/releases.html
https://github.com/opencv/opencv_contrib/tree/3.4.0
4、安装opencv3.4.0
1.配置选项
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.0/modules \
-D PYTHON_EXECUTABLE=/usr/bin/python3 \
-D BUILD_EXAMPLES=ON ..curl
2.编译
make -j4测试
-j4表示四核运算,可根据电脑配置选择 若是出现错误,改成单核执行ui
make cleanurl
make
3.安装
sudo make install
5、测试
1.python测试
打开一个新的终端,输入python3
import cv2 as cv
print(cv.version)
输出 '3.4.0' ,说明python环境正常
2.opencv自己测试
下载测试数据 git clone https://github.com/opencv/opencv_extra.git
设置 OPENCV_TEST_DATA_PATH为<path to opencv_extra/testdata>
运行 <cmake_build_dir>/bin/opencv_test_core
6、错误解决
1.fatal error: boostdesc_bgm.i: No such file or directory
该问题是因为cmake不支持https引发的,能够查看CMakeDownloadLog.txt文件,cmake须要下载,可是失败了。
解决办法:
从新编译cmake,支持https,或者手动下载文件
sudo apt-get install libcurl4-openssl-dev
./bootstrap --system-curl
make
sudo make install