1. 安装必需的包
我们先清除x264、ffmpeg及其相关的包,然后手动编译安装这两个包。具体参考这篇博文 x264和ffmpeg的安装。
安装用于构建debian包的依赖
sudo aptitude install build-essential cmake git pkg-config
安装图像处理依赖
sudo aptitude install python-dev libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
视频处理依赖
sudo aptitude install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev
图形界面依赖
sudo aptitude install libgtk2.0-dev libgtk-3-dev
高性能计算依赖
sudo aptitude install libatlas-base-dev gfortran pylint
gstreamer依赖
sudo aptitude install libgstreamer1.0-0 libgstreamer1.0-dev gstreamer1.0-tools gstreamer1.0-plugins-base libgstreamer-plugins-base1.0-dev gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-plugins-bad gstreamer1.0-ffmpeg libgstreamer0.10-0 libgstreamer0.10-dev gstreamer0.10-tools gstreamer0.10-plugins-base libgstreamer-plugins-base0.10-dev gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-ffmpeg
python依赖
sudo aptitude install python2.7-dev python3.5-dev python-numpy
2. 下载opencv
opencv下载地址https://opencv.org/releases/
opencv_contrib下载地址https://github.com/opencv/opencv_contrib/tree/3.4 (包含很多有用的算法)
unzip opencv-3.4.5.zip; unzip opencv-3.4.zip
3. 安装opencv
配置opencv
cmake -DWITHLAPACK=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4/modules -DOPENCV_ENABLE_NONFREE=True ..
因为在Ubuntu14 64位 CUDA的环境下,libatlas会造成opencv出错,因此取消了对libatlas的依赖。把安装位置设置在/usr/local,外部模块的位置在../../opencv_contrib-3.4/modules。
编译安装opencv,并更新动态链接库配置。
make j 24 && sudo make install && sudo ldconfig
4. 修改动态链接库配置
在/etc/ld.so.config文件中的单独一行加入/usr/local/lib/x86_64-linux-gnu/。然后
sudo ldconfig
然后新安装的opencv就可以被其他包编译使用了。