前言
Ubuntu上我们一般需要安装opencv来完成图像处理等程序操作,下面我以opencv3.4.0在Ubuntu16.04上的安装为例进行讲解。
1. 系统自带opencv
Ubuntu16.04系统资源库自带opencv2.4.8
,如果不需要用到高级功能,这点即可。其下载方法如下:
1 | sudo apt install libopencv-dev |
判断系统上是否存在opencv,可输入:
1 | pkg-config --modversion opencv |
卸载方法为:
1 | sudo apt remove libopencv-dev |
2.官网下载安装opencv
2.1 安装opencv
Step1 卸载已有opencv
Step2 进入Opencv官网选择对应版本
source
下载。Step3 在下载路径执行:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31if [ ! -d "opencv-3.4.0/" ];then
unzip opencv-3.4.0.zip -d ./
else
echo "opencv package has been unzipped"
fi
sudo apt-get install cmake pkg-config build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev -y
cd opencv-3.4.0/
sudo mkdir build
cd build
sudo make clean
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make -j8
sudo make install
if [ 0 -eq $(cat /etc/ld.so.conf.d/opencv.conf | grep -c '/usr/local/lib') ] ;then
echo '/usr/local/lib' >> /etc/ld.so.conf.d/opencv.conf
fi
if [ 0 -eq $(cat /etc/bash.bashrc | grep -c 'PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig') ] ;then
echo 'PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig' >> /etc/bash.bashrc
fi
if [ 0 -eq $(cat /etc/bash.bashrc | grep -c 'export PKG_CONFIG_PATH') ] ;then
echo 'export PKG_CONFIG_PATH' >> /etc/bash.bashrc
fi
sudo ldconfig
sudo updatedb
source /etc/bash.bashrcStep4 如果安装过程中卡在
ippicv
这里,可以去这里下载,然后重命名为4e0352ce96473837b1d671ce87f17359-ippicv_2017u3_lnx_intel64_general_20170822.tgz
,放入opencv-3.4.0/.cache/ippicv/
下,重新安装。
2.2 卸载opencv
卸载方法如下,进入下载路径:
1 | cd opencv-3.4.0/build |
3.python版opencv
python版本的opencv可通过pip
直接下载安装,pip
下载源建议设置为国内源,即在当前用户HOME
目录下新建一个.pip/pip.conf
文件,写入:
1 | [global] |
然后下载安装python-opencv
:
1 | pip install opencv-python |
卸载方式:
1 | pip uninstall opencv-python |