1、安装cmake:sudo apt-get install cmake

## 依赖项& 环境搭建

“`

    sudo apt-get install build-essential cmake pkg-config

    sudo apt-get install cmake git libgtk2.0-dev pkg-config
libavcodec-dev libavformat-dev libswscale-dev

    sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev
libjpeg-dev libpng-dev libtiff5-dev libjasper-dev libdc1394-22-dev

“`

– [参考网站] :

– [libjasper-dev] :

    “`

    sudo aptitude install python-opencv

    – perl: warning: Setting locale failed

    export LC_ALL=C 

    “`

    from:

## 获取opencv 源代码

– 源代码下载 :

## 编写翻译源代码

### 进入opencv源代码目录,在该目录中新建八个名为release的文件夹。

    “`

    cd ~/opencv/opencv-2.4.9

    mkdir release

    cd release

    “`

   
使用cmake工具在该文件夹中生成makefile文件,钦赐opencv的装置目录为/usr/local,opencv的源代码位于上一层目录。

    “`

    cmake -D CMAKE_BUILD_TYPE=RELEASE -D
CMAKE_INSTALL_PREFIX=/usr/local ..

    “`

### 假若cmake阶段一贯停在下载IPPICV那里,则按Ctrl C撤除

    手动下载ippicv_2017u3_lnx_intel64_general_20170822.tgz

   

###
然后进入~/Downloads/opencv3.3.1文本夹创立八个.cache文件夹,并拷贝相应的公文: 

    “`

    cd ~/Downloads/opencv3.3.1

    ipp_file=ippicv_2017u3_lnx_intel64_general_20170822.tgz &&
ipp_hash=$(md5sum ~/Downloads/$ipp_file | cut -d” ” -f1) &&
ipp_dir=.cache/ippicv && mkdir -p ${ipp_dir} && cp
~/Downloads/$ipp_file $ipp_dir/$ipp_hash-$ipp_file

    “`

### 然后再度运营编写翻译命令和安装命令:

    “`

    cd ~/Downloads/opencv3.3.1/build

    sudo cmake -D CMAKE_BUILD_TYPE=DEBUG -D
CMAKE_INSTALL_PREFIX=/usr/local ..

  sudo make

    sudo make install

    “`

    sudo apt-get install build-essential cmake pkg-config

    sudo apt-get install cmake git libgtk2.0-dev pkg-config
libavcodec-dev libavformat-dev libswscale-dev

    sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev
libjpeg-dev libpng-dev libtiff5-dev libjasper-dev libdc1394-22-dev

    “`

– [参照网站] :

– [libjasper-dev] :

    “`

    sudo aptitude install python-opencv

    perl: warning: Setting locale failed

    export LC_ALL=C 

澳门金沙国际,    “`

    from:

## 获取opencv 源代码

– 源代码下载 :

## 编写翻译源代码

### 进入opencv源代码目录,在该目录中新建3个名为release的文本夹。

    “`

    cd ~/opencv/opencv-2.4.9

    mkdir release

    cd release

    “`

   
使用cmake工具在该公文夹中生成makefile文件,钦点opencv的安装目录为/usr/local,opencv的源代码位于上一层目录。

    “`

    cmake -D CMAKE_BUILD_TYPE=RELEASE -D
CMAKE_INSTALL_PREFIX=/usr/local ..

    “`

### 要是cmake阶段一贯停在下载IPPICV那里,则按Ctrl C撤消

    手动下载ippicv_2017u3_lnx_intel64_general_20170822.tgz

   

###
然后跻身~/Downloads/opencv3.3.1文书夹创制一个.cache文件夹,并拷贝相应的文书: 

    “`

    cd ~/Downloads/opencv3.3.1

    ipp_file=ippicv_2017u3_lnx_intel64_general_20170822.tgz &&
ipp_linux下编写翻译opencv。hash=$(md5sum ~/Downloads/$ipp_file | cut -d” ” -f1) &&
ipp_dir=.cache/ippicv && mkdir -p ${ipp_dir} && cp
~/Downloads/$ipp_file $ipp_dir/$ipp_hash-$ipp_file

    “`

### 然后再一次运转编写翻译命令和设置命令:

    “`

    cd ~/Downloads/opencv3.3.1/build

    sudo cmake -D CMAKE_BUILD_TYPE=DEBUG -D
CMAKE_INSTALL_PREFIX=/usr/local ..

  sudo make

    sudo make install

    “`

1.装置 opencv 所需依靠包

一旦后边还要遗漏的,出错再补上

$ sudo apt-get update
$ sudo apt-get upgrade
$ 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 libtiff5-dev libjasper-dev
libavcodec-dev libavformat-dev libswscale-dev libxine2-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
x264v4l-utils unzip

第一遍尝试,太天真

2、下载opencv-2.4.10.zip,解压

2.下载 opencv3.2.0

那里需求下载 opencv 和 opencv_contrib (后者会在 cmake 配置的时候使用),
那是因为 opencv3现在 SIFT 和 SU库罗德F 之类的性质被移到了 contrib
中,执行上边两条指令下载 OpenCV3.2.0

$ wget
https://github.com/opencv/opencv/archive/3.2.0.zip
$ wget
https://github.com/opencv/opencv\_contrib/archive/3.2.0.zip

(3.2.0.zip就是opencv-3.2.0.zip)
(3.2.0.zip.1就是opencv_contrib.zip)

一,更新ubuntu软件源

sudo apt-get update

3、编译opencv

3.解压下载的八个文本

$ unzip opencv-3.2.0.zip -d ~/opencv
$ unzip opencv_contrib-3.2.0.zip -d ~/opencv

二,opencv安装

sudo apt-get install libcv-dev

ps:删除配置文件

cd /var/cache/apt/archives
sudo apt-get clean

cd /home/opencv-2.4.10

4.成立并跻身 build 目录,执行 cmake 生成 makefile 文件

$ cd ~/opencv/opencv-3.2.0
$ mkdir build
$ cd build/
$ sudo cmake -D CMAKE_BUILD_TYPE=Release -D
CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH= ..

注意cmake的参数不要出错

接下来尝试

import cv2

应有尽有的老大(
————————-分割——————————–

mkdir build

问题一:

下载包的时候链接超时

CMake Error at 3rdparty/ippicv/downloader.cmake:77 (message):
  ICV: Failed to download ICV package: ippicv_linux_20151201.tgz.
  Status=28;"Timeout was reached"

手动下载
ippicv_linux_20151201.tgz(https://raw.githubusercontent.com/Itseez/opencv\_3rdparty/81a676001ca8075ada498583e4166079e5744668/ippicv/ippicv\_linux\_20151201.tgz)到opencv-3.2.0/3rdparty/ippicv/downloads/目录下再cmake

$ sudo cp ~/software/opencv/ippicv_linux_20151201.tgz
~/opencv/opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/

其次次尝试

cd build/

问题二:

-- No package 'gtk+-3.0' found

$ sudo apt-get install libgtk-3-dev

1.opencv的连带正视

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

下载
opencv3.2)

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

问题三:

--   No package 'gstreamer-base-1.0' found

--   No package 'gstreamer-video-1.0' found

--   No package 'gstreamer-app-1.0' found

--   No package 'gstreamer-riff-1.0' found

--   No package 'gstreamer-pbutils-1.0' found

sudo apt-get -y install libgstreamer-plugins-base1.0-dev
sudo apt-get -y install libgstreamer1.0-dev

2.编写翻译安装

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

cd /home/yewii/下载
unzip opencv-3.3.0.zip
cd opencv-3.3.0

四 、结束后输入sudo make

问题四:

--   No package 'libavresample' found

--   No package 'libgphoto2' found

$ sudo apt-get -y install libavresample-dev
$ sudo apt-get -y install libgphoto2-dev

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-阿尔法文件夹中的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。然后下载编写翻译一样越发!

————————-分割——————————–

⑤ 、然后在输入sudo make install

问题五:

-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
-- Could NOT find Atlas (missing:  Atlas_CBLAS_INCLUDE_DIR Atlas_CLAPACK_INCLUDE_DIR Atlas_CBLAS_LIBRARY Atlas_BLAS_LIBRARY Atlas_LAPACK_LIBRARY) 
-- Could NOT find Doxygen (missing:  DOXYGEN_EXECUTABLE) 
-- Could NOT find JNI (missing:  JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH) 
-- Could NOT find Matlab (missing:  MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIRS MATLAB_ROOT_DIR MATLAB_LIBRARIES MATLAB_LIBRARY_DIRS MATLAB_MEXEXT MATLAB_ARCH MATLAB_BIN) 
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file

$ sudo apt-get install libopenblas-dev

第N次尝试,真的,快到头的感到

觉得是opencv包和原先的有冲突,就悟出搭建贰个沙盒。

前注:安装OpenCv
3.1的进程中要下载ippicv_linux_20161201,由于互联网的原由,这么些文件日常会下载失利,作者就蒙受了,后边会讲到。

陆 、那样就编写翻译完结了,你能够在usr/local/lib下观察编写翻译好的opencv函数库

问题六:

-- Could NOT find Doxygen (missing:  DOXYGEN_EXECUTABLE) 

$ sudo apt-get install doxygen

一,老规矩,各类库和包文件更新和设置

$ 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

问题七:

-- Could NOT find JNI (missing:  JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH) 

a.下载jdk-8u151-linux-x64.tar.gz到download目录
http://www.oracle.com/technetwork/cn/java/javase/downloads/jdk8-downloads-2133151-zhs.html

b.安装jdk

$ cd download/
$ sudo mkdir /usr/local/java
$ sudo tar zxvf jdk-8u151-linux-x64.tar.gz -C /usr/local/java
$ sudo ln -s /usr/local/java/jdk1.8.0_151/ /usr/local/java/latest

c. 添加环境变量:

$ sudo vim /etc/profile

进入如下内容:

>export JAVA_HOME=/usr/local/java/latest
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

执行

$ source /etc/profile

拓展翻新。

一贯不报错的事态下,cmake成功后会出现

-- Configuring done
-- Generating done
-- Build files have been written to: /home/fc/opencv/opencv-
3.2.0/build

二,下载文件,解压文件并跻身

下载链接opencv

unzip opencv.zip

下载opencv_contrib

unzip opencv_contrib.zip

5. make

cmake成功,之后方可在 build
文件下实施编写翻译指令,待编写翻译成功后即可举行安装指令。

$ sudo make -j4

出错:
/opencv/opencv-3.2.0/build/opencv_lapack.h:2:45: fatal error:
LAPACKE_H_PATH-NOTFOUND/lapacke.h: 没有那么些文件或目录
缓解方式:

$ sudo apt-get install liblapacke-dev checkinstall

make时间有点长,大致多个小时了。

三,安装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

6.install

$ sudo make install

四,配置和编写翻译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_二零一四1201并发难题,化解:

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

7.装置 python 接口依赖

$sudo apt-get install python-opencv
sudo apt-get install python-numpy

五,完成opencv安装

在运维sudo make
install后,你的OpenCV+Python3的包扎应在/usr/local/lib/python3.5/site-packages/,再度验证那些动用ls命令:

ls -l /usr/local/lib/python3.5/site-packages/

出现toatal ***就对着

8.测试 Python 的 OpenCV3.2.0 模块

$ python
Python 2.7.14 |Anaconda, Inc.| (default, Oct 16 2017, 17:29:19) 
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ImportError: No module named cv2
>>> 

问题:No module named cv2
由来在于 python2.7 找不到 cv2.so 文本

$ sudo cp ~/opencv/opencv-3.2.0/build/lib/cv2.so
~/anaconda2/lib/python2.7/site-packages/

再测试:

$ python
Python 2.7.14 |Anaconda, Inc.| (default, Oct 16 2017, 17:29:19) 
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.2.0'
>>> 

能显得opencv的本子表达安装成功

六,测试

开辟一个新的顶点,进入cv的虚拟环境

python

import cv2

没报错,哈哈哈哈,终于成了。

开门红,明晚吃鸡

相关文章