ubuntu安装opencv3.4.0+opencv-contrib3.4.0

一,安装依赖
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

sudo apt-get install –assume-yes libopencv-dev libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip

sudo apt-get install ffmpeg libopencv-dev libgtk-3-dev python-numpy python3-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libv4l-dev libtbb-dev qtbase5-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev
为了保险,把依赖都安装上!

一般情况下,只需安装:

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
sudo apt-get install ffmpeg

二,下载opencv3.4.0+opencv-contrib3.4.0
https://github.com/opencv
点击opencv–>选择release–>选择opencv3.4.0
用同样的方法下载opencv-contrib3.4.0
注意:opencv和opencv-contrib的版本必须一致!
把opencv.zip和opencv_contrib.zip成文件夹,把opencv_contrib文件夹放在opencv文件夹中

三,安装opencv3.4.0+opencv-contrib3.4.0
1.执行

cmake --version

查看cmake是否安装,如果没有安装的话,按照他提示的命令按照即可。Ubuntu16.04自带了3.5.1版本的cmake。按照其他版本的话,可能会出错,我这里遇到了一些错误。

sudo apt-get install cmake 

2.进入opencv目录,并在opencv-3.4.0目录下建一个build文件夹

cd opencv-3.4.0
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.4.0/modules ..

安装opencv-contrib包,必须要有OPENCV_EXTRA_MODULES_PATH
如果不执行的话,命令前面加个sudo再试一下。
3.配置成功以后,make一下

sudo make -j8

8核同时编译,速度会快一些!
ubuntu安装opencv3.4.0+opencv-contrib3.4.0_第1张图片
4.make成功之后,执行

sudo make install

opencv安装成功
ubuntu安装opencv3.4.0+opencv-contrib3.4.0_第2张图片
四,配置opencv,添加路径

sudo gedit /etc/ld.so.conf.d/opencv.conf

在最后添加如下路径

/usr/local/lib

保存之后执行

sudo ldconfig
sudo vim /etc/bash.bashrc

在末尾添加如下内容:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

source一下,使修改立即生效。

source /etc/bash.bashrc

五,测试一下opencv
1.在samples/cpp/example_cmake下,执行:

cmake .
make
./opencv_example

ubuntu安装opencv3.4.0+opencv-contrib3.4.0_第3张图片

六,遇到的问题
1、遇到没有.i文件,是由于在cmake的时候,网络原因,东西没有下载下来。看看你的build文件夹中是否包含,downloads文件夹。
ubuntu安装opencv3.4.0+opencv-contrib3.4.0_第4张图片解决方法:删除build文件夹,重新试一下看行不行,应该是网络问题。我用了cmake3.13有问题,之后用了cmake3.9的还是不行,但是最后用了cmake3.5.1的就成功啦。很迷…
2.遇到这个问题可能是cuda版本的问题,我要跑opencv的tracking代码,所以使用的是cuda8,查看一下cuda版本。
ubuntu安装opencv3.4.0+opencv-contrib3.4.0_第5张图片
注:我安装的时候遇到了很多问题,最后重装了系统,只要把显卡驱动,cuda,cudnn安装好对应版本的,cmake用3.5.1,应该就能一次安装成功。

你可能感兴趣的:(opencv)