基于ubuntu16.04系统下OpenCV源码安装及无法import cv2

开篇

OpenCV: Open Source Computer Vision Library
官网:http://opencv.org/
github:https://github.com/opencv/opencv
Openvc是一个由许多算法组成的处理图片的库,算法基本由C++以及少部分的C写成。并且提供大量的编程语言接口,如:Python, Java and MATLAB/OCTAVE (版本2.5)等。

安装准备

系统:Ubuntu16.04
opencv的相关依赖:

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

cmake 是一个跨平台的编译工具,对C++支持的特别好。

下载

地址:https://sourceforge.net/projects/opencvlibrary/files/latest/download?source=typ_redirect 我下载的是3.2(最新)版本的

编译安装

打开终端,进入下载目录,并解压进入目录:

cd python
zip opencv-3.2.0
cd opencv-3.2.0

执行如下命令:

 cmake . 
 #注意:不要弄成cmake/ . 

注意:如果您遇到散列不匹配错误,请从sourceforge手动下载文件ippicv_linux_20140513.tgz

下载文件后,将内容解压缩到opencv-3.0.0-alpha文件夹中的ippicv文件夹。
继续,。。。。。报错:

Checking for module 'gtk+-3.0'
--   No package 'gtk+-3.0' found
-- Checking for module 'gstreamer-base-1.0'
--   No package 'gstreamer-base-1.0' found

少库,安转,

 sudo apt-get install libgt.......
 #少多少就加多少,报错一直安装,直到如下报错
  checking for module 'gstreamer-base-1.0'
--   package 'gstreamer-base-1.0' not found
-- checking for module 'gstreamer-video-1.0'
--   package 'gstreamer-video-1.0' not found
-- checking for module 'gstreamer-app-1.0'
--   package 'gstreamer-app-1.0' not found
-- checking for module 'gstreamer-riff-1.0'
--   package 'gstreamer-riff-1.0' not found
-- checking for module 'gstreamer-pbutils-1.0'

于是我

sudo apt-get install libgstreamer1.0-dev

结果无法解决,网上没有,去官网https://gstreamer.freedesktop.org/download/找了说,

Download GStreamer

In general, you should find packages that were specifically made for your distribution. Do not compile from source yourself unless you are certain you have to or want to. Do not compile from Git unless you really need some specific feature that is not released yet, or want to help out developing GStreamer.

Linux
Most, if not all, Linux distributions provide packages of GStreamer. You should find these in your distribution’s package repository.
Note that some distributions split the GStreamer plugins up further than the upstream sources. Additionally, some distributions do not include the gst-plugins-bad, gst-plugins-ugly, and gst-libav packages in their main repository, for legal reasons.
OpenBSD
Packages for various architectures are available, see the OpenBSD ports page.
Windows
MSI installers for Windows can be found here. They are provided and maintained by the GStreamer project.
Mac OS X
A .framework for Mac OS X can be found here. It is provided and maintained by the GStreamer project.
Android
Binaries for GStreamer on Android that integrate into the Android NDK can be found here. They are provided and maintained by the GStreamer project.
iOS
Binaries for GStreamer on iOS that integrate into XCode can be found here. They are provided and maintained by the GStreamer project.
Symbian
The sources of the initial port of GStreamer are available for download.
Releated binary packages are also available.
Source
Check our modules page, or go straight to our source download directory.

ubuntu 直接通过apt-get 安装,但是找不到,只有去Sources download。然后下载编译一样不行。


成功的分界线

通过google在stackoverflow找到了一篇nice的文章地址在这。成功的解决了我的问题,具体步骤如下:

# step 1 
# 安装依赖 (太多了,自己相应替换)
sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-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 -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-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 --fix-missing


# step 2
# 下载解包
wget https://github.com/Itseez/opencv/archive/3.0.0-alpha.zip
unzip opencv-3.0.0-alpha.zip
# step 3
# 编译
cd opencv-3.0.0-alpha
mkdir build
cd build
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 ..
# step 4
#安装
make 
sudo make install

# step 5
# 安装完成,进行整理 
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
sudo apt-get update

写个Python文件 :

 import cv2 
#没有报错了,啊哈哈,

不仅解决了安装opencv的问题还解决了import cv2 的问题,因为在网上都说还得把一个包加入到另一个地方 ,就是将Opencv安装目录下opencv\build\python\2.7\x86中的cv2.pyd复制到python安装目录Lib\site-packages下。
nicegood
我的博客地址http://blog.csdn.net/tengxing007

不得不说stackoverflow真的是个好东西,google对于开发人员来说真的很重要,最主要的还是对于bug的理性认知,和分析,解决。
参考文献:
http://stackoverflow.com/questions/25726768/opencv-3-0-trouble-with-installation
http://www.linuxidc.com/Linux/2016-07/132879.htm
http://www.linuxidc.com/Linux/2013-06/86704.htm
http://blog.csdn.net/sparkexpert/article/details/51736978

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付 9.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值