第一次尝试,太天真
一,更新ubuntu软件源
sudo apt-get update
二,opencv安装
sudo apt-get install libcv-dev
ps:删除配置文件
cd /var/cache/apt/archives
sudo apt-get clean
然后尝试
import cv2
完美的不行(-)
-------------------------分割--------------------------------
第二次尝试
1.opencv的相关依赖
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev cmake libswscale-dev libjasper-dev
下载
opencv3.2
2.编译安装
打开终端,进入下载目录,并解压进入目录:
cd /home/yewii/下载
unzip opencv-3.3.0.zip
cd opencv-3.3.0
3.然后
cmake .
报错
CMake Error at CMakeLists.txt:11 (message): FATAL: In-source builds are not allowed. You should create separate directory for build files. -- Configuring incomplete, errors occurred!
然后从sourceforge手动下载文件ippicv_windows_20141027.zip
下载文件后,将内容解压缩到opencv-3.3.0-alpha文件夹中的ippicv文件夹。
继续,。。。。。报错:
Checking for module 'gtk+-3.0' Checking:未找到命令
呵呵,又失败
去官网看Download GStreamer
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.
ubuntu 直接通过apt-get 安装,但是找不到,只有去Sources download。然后下载编译一样不行!
-------------------------分割--------------------------------
第N次尝试,真的,快绝望的感觉
觉得是opencv包和以前的有冲突,就想到搭建一个沙盒。
前注:安装OpenCv 3.1的过程中要下载ippicv_linux_20151201,由于网络的原因,这个文件经常会下载失败,我就遇到了,后面会讲到。
一,老规矩,各种库和包文件更新和安装
$ sudo apt-get update
$ sudo apt-get upgrade
安装cmake,用来配置opencv build
$ sudo apt-get install build-essential cmake pkg-config
$ sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev
从视频流和相机中获取文件
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev
opencv GUI操作处理的模块名为highgui,而这个模块依赖于GTK库
$ sudo apt-get install libgtk-3-dev
安装在opencv中用来优化函数的库
sudo apt-get install libatlas-base-dev gfortran
安装完python3.5的头文件和库
sudo apt-get install python3.5-dev
二,下载文件,解压文件并进入
下载链接opencv
unzip opencv.zip
unzip opencv_contrib.zip
三,安装python环境
cd ~
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
使用virtualenv 和 virtualenvwrapper
sudo pip install virtualenv virtualenvwrapper
sudo rm -rf ~/get-pip.py ~/.cache/pip
安装完virtualenv 和 virtualenvwrapper后,我们需要更新我们的~/.bashrc
virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
重新加载变化
source ~/.bashrc
创建你的Python虚拟环境
mkvirtualenv cv -p python3
现在检验是否进入"cv",如果进入,终端前会有(cv)
如果没有
workon cv
在虚拟环境中安装NumPy
pip install numpy
四,配置和编译opencv
注意:在我们开始前,再次确认你是在cv的虚拟环境中
接下来我们使用CMake来安装和配置我们的build:
cd ~/opencv-3.1.0/
mkdir build
cd build
预编译cmake
cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D INSTALL_PYTHON_EXAMPLES=ON
-D INSTALL_C_EXAMPLES=OFF
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules
-D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python
-D BUILD_EXAMPLES=ON ..
然后下载ippicv_linux_20151201出现问题,解决:
1.下载ippicv_linux_20151201
2.进入opencv目录
mkdir -p $ipp_dir &&
cp $ipp_file $ipp_dir
创建ippicv_linux_20151201的目录,带MD5.
ipp_file=../ippicv_linux_20151201.tgz &&
ipp_hash=$(md5sum $ipp_file | cut -d" " -f1) &&
ipp_dir=3rdparty/ippicv/downloads/linux-$ipp_hash &&
如果CMake命令退出时没有出现错误,继续编译
make clean
make
sudo make install
sudo ldconfig
五,完成opencv安装
在运行sudo make install后,你的OpenCV+Python3的捆绑应在/usr/local/lib/python3.5/site-packages/,再次验证这个使用ls命令:
ls -l /usr/local/lib/python3.5/site-packages/
出现toatal ***就对着
六,测试
打开一个新的终端,进入cv的虚拟环境
python
import cv2
没报错,哈哈哈哈,终于成了。
网友评论