在ubuntu16.04下安装opencv3.4.5(超详细)

一、编译安装
1.官网下载sources版本(For Linux):http://opencv.org/releases.html

2.解压:

unzip opencv-3.4.5.zip

3.进入:

cd opencv-3.4.5

(如果安装的文件在本机上,则先进入此安装包所在路径,比如我的下载到了本机上的c盘中,则进入“cd /mnt/c/opencv-3.4.5”)

4.安装cmake工具:

sudo apt-get install cmake

(在这个地方可能会因为网络的原因遇到问题,多试几次)
运行完这个命令行之后,可能会出现问题Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?解决方法如下:
第一种:
sudo vim /etc/resolv.conf
添加nameserver 8.8.8.8
第二种:
/etc/apt/sources.list 的内容换成
deb http://old-releases.ubuntu.com/ubuntu/ raring main universe restricted multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring main universe restricted multiverse
deb http://old-releases.ubuntu.com/ubuntu/ raring-security main universe restricted multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring-security main universe restricted multiverse
deb http://old-releases.ubuntu.com/ubuntu/ raring-updates main universe restricted multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring-updates main universe restricted multiverse
deb http://old-releases.ubuntu.com/ubuntu/ raring-backports main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring-backports main restricted universe multiverse
deb http://old-releases.ubuntu.com/ubuntu/ raring-proposed main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring-proposed main restricted universe multiverse

然后sudo apt-get update一下
参考:https://blog.csdn.net/tiny_lxf/article/details/75027865

5.安装依赖库:

sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev

6.创建编译目录(release)并进入:

mkdir release && cd release

7.cmake配置编译:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

8.make编译:

make -j$(nproc) // nproc是读取CPU的核心数量 

9.安装:

sudo make install

10.环境配置添加库路径(方式一):

sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'

10.环境配置添加库路径(方式二):

sudo gedit /etc/ld.so.conf.d/opencv.conf 
//打开后可能是空文件,在文件内容最后添加
/usr/local/lib

11.更新系统库:

sudo ldconfig

12.配置bash,执行如下命令

sudo gedit /etc/bash.bashrc  
//在末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig  4 export PKG_CONFIG_PATH

保存退出,然后执行如下命令使得配置生效

sudo source /etc/bash.bashrc
//激活配置然后更新database
sudo updatedb  

可能会遇到问题sudo: source: command not found,这时可如下2步处理(如图):
1> sudo -s
2> source /etc/profile
在ubuntu16.04下安装opencv3.4.5(超详细)_第1张图片
别的问题:
1.Qt5Core编译错误
Qt5Core-CMake did not find one
解决方式:
qt5-default:sudo apt-get install qt5-default

参考:https://www.cnblogs.com/Shuqing-cxw/p/9195303.html

你可能感兴趣的:(在ubuntu16.04下安装opencv3.4.5(超详细))