Ubuntu16.04+Opencv3.3的安装教程

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Ubuntu16.04+Opencv3.3的安装教程
需要准备的基本材料(请先看完整个安装过程再进⾏下⾯的操作):
⼀、到Opecv-Release的Github项⽬上下载最新的Opencv版本,注意---基于python2.7,可选⽤ OpenCV2.3/2.4 以及 OpenCV3.X,我们选取版本3.3:下载地址:
⼆、安装GUN GCC编译器,对于Ubuntu16.04版本的Linux操作系统这款编译器是⾃带的
三、安装Cmake跨平台编译⼯具(CMake 可以编译、制作程序库、产⽣适配器(wrapper)、还可以⽤任意的顺序建构)安装的⽅法:sudo apt-get install cmake
我已经安装好了,就提⽰⽆需更新,⽆需安装
四、安装python2.7,在ubuntu中⼀般来说是⾃带python2.7的,如果没有安装,请参看博客中其他的教程
五、安装numpy,在安装好python之后建议您安装pip,安装完pip之后就可以使⽤pip来安装各种各样的库了,pip install numpy
我已经安装好了,就提⽰⽆需更新,⽆需安装
六、安装pkg-config指令(注意,这⾥的安装很重要,例如libgtk2.0-dev软件包涉及到了opencv中的imshow等窗⼝调⽤能否使⽤的问题):sudo apt-get install pkg-config libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
开始安装Opencv For Python:
1、找到下载的Opencv3.3的⽬录:
2、执⾏下⾯的指令(在执⾏指令的过程之前,我们可以切换到su超级权限下进⾏操作,也可以不切换到su权限下,切换到那个⽤户,以后就只能在那个⽤户下调⽤对应的cv2的图像处理库):
tar -xzvf opencv-3.3.0.tar.gz
cd opencv-3.3.0/
cd ..
mkdir my_build_dir
cd my_build_dir
cmake ../opencv-3.3.0 -DWITH_GTK_2_X=ON -DCMAKE_INSTALL_PREFIX=/usr/local
make # make -j4表⽰开4个线程来进⾏编译
make install
解压之后的opencv-3.3.0的⽬录:
Cmake的过程和结果如下:
建⽴的my_build_dir经过 cmake ../opencv-3.3.0 -DWITH_GTK_2_X=ON -DCMAKE_INSTALL_PREFIX=/usr/local之后的结果
在my_build_dir中执⾏make和make install即可
编写代码:
运⾏结果:
安装过程之中碰到的问题:
"FATAL: In-source builds are not allowed.
You should create separate directory for build files."
意思就是说不要在源代码内部直接编译程序,以免污染源代码,所以在opencv-2.4.13⽬录之外建⽴⽂件夹my_build_dir,然后在这个⽬录⾥⾯执⾏cmake。

详细问题参照下⾯的链接:
Ubuntu下卸载重装Opencv的教程参考:
注:安装之后可能遇到的问题
Question-1:
简单的意思就是调⽤了window相关的程序,但是没有安装GTK相关的包,函数function不能实现,需要安装libgtk2.0-dev 和 pkg-config。

如果没有使⽤到opencv的显⽰接⼝的话,基本的opencv的函数是能够使⽤的,在通过numpy的相关的数学运算包转化⼀下数据格式就可以使⽤matlibplot 等包显⽰输出图像了。

如果想解决上述的问题,就⼀定记得安装libgtk2.0-dev和pkg-config之后在cmake ---》make ---》 make install.Opencv就⾏了。

Question-2:
我们发现在安装libgtk2.0-dev的软件包的时候,很难安装成功,全是提⽰说安装包和其他的依赖的安装包存在版本不兼容的问题,如下图所⽰:
# apt-get install libgtk2.0-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
libgtk2.0-dev: Depends: libgtk2.0-0 (=2.20.0-0ubuntu4) but 2.20.1-0ubuntu2.1is to be installed
Depends: libglib2.0-dev (>=2.21.3) but it is not going to be installed
Depends: libpango1.0-dev (>=1.20) but it is not going to be installed
Depends: libatk1.0-dev (>=1.13.0) but it is not going to be installed
Depends: libcairo2-dev (>=1.6.4-6.1) but it is not going to be installed
Depends: libx11-dev (>=2:1.0.0-6) but it is not going to be installed
Depends: libxext-dev (>=1:1.0.1-2) but it is not going to be installed
Depends: libxinerama-dev (>=1:1.0.1-4.1) but it is not going to be installed
Depends: libxi-dev (>=1:1.0.1-4) but it is not going to be installed
Depends: libxrandr-dev (>=1:1.2.99) but it is not going to be installed
Depends: libxcursor-dev but it is not going to be installed
Depends: libxfixes-dev (>=1:3.0.0-3) but it is not going to be installed
Depends: libxcomposite-dev (>=1:0.2.0-3) but it is not going to be installed
Depends: libxdamage-dev (>=1:1.0.1-3) but it is not going to be installed
E: Broken packages
将较新的库降级为满⾜依赖关系的库,按照提⽰逐步操作即可。

这⾥我们就需要使⽤如下的指令来完成安装:
sudo aptitude install libgtk2.0-dev
运⾏后会出现⼀⼤堆消息,给出第⼀个解决⽅案⼀般是保留这些库⽂件,让选择y/n/q?,这⾥选择“n”;然后会继续找解决⽅案,有时会超时找不到,点击y 继续找,直到给出得解决⽅案是“降级”这些库⽂件,选择“y”,然后等待结束就完了。

这⾥我们看到提⽰:Setting up libgtk2.0-dev(2.24.25-3+deb8u2) ...
完成后可以再输⼊“sudo apt-get install libgtk2.0-dev”进⾏测试,出现已经安装对应得库⽂件,说明安装成功了。

(此⽅法同样适⽤于安装opencv时其他不能正常安装的预备库⽂件)
Finished!。

相关文档
最新文档