Ubuntu1604装机系列(二):Opencv安装

下载

官网下载opencv3.4.1,选择source版本
官网下载opencv3.4.1_contrib,选择source版本

首先安装必要的依赖

1
sudo apt-get -qq install libopencv-dev build-essential checkinstall cmake pkg-config yasm libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils

编译安装opencv

1
2
3
4
5
6
7
8
cp ../opencv3.4.1_contrib ./   # 复制contrib到opencv3.4.1文件夹并重命名
cd opencv3.4.1
mv opencv3.4.1_contrib opencv_contrib
mkdir buildc
cd build
cmake ..
ccmake ..
几个要注意的修改项(cuda/python根据自己的安装路径来写):
1
2
3
4
5
6
7
8
CUDA_TOOLKIT_ROOT_DIR:		/home/<user name>/wuxj/cuda-8.0
OPENCV_EXTRA_MODULES_PATH: /home/<user name>/wuxj/opencv-3.4.1/opencv_contrib/modules
PYTHON2_EXECUTABLE: /usr/bin/python2.7
PYTHON2_INCLUDE_DIR: /usr/include/python2.7
PYTHON2_LIBRARY: /usr/lib/x86_64-linux-gnu/libpython2.7.so
PYTHON2_NUMPY_INCLUDE_DIRS: /usr/local/lib/python2.7/dist-packages/dist-packages/numpy/core/include
PYTHON2_PACKAGES_PATH: lib/python2.7/dist-packages
CMAKE_INSTALL_PREFIX: /home/<user name>/wuxj # make install的安装路径

make -j8 # 等待安装成功即可 8:8核CPU,编译速度更快

make install # 复制上一步build文件夹到/home/<user name>/wuxj 中,这时候wuxj文件夹会包含bin(exe)、include(头文件)、lib(动态库)、share4个文件夹