opencv3.2 安装说明书

opencv3.2 安装说明书

软件环境

ubuntu 14,04 python2.7 cmake , g++, gcc

1 安装OpenCV依赖

1.1 升级系统

$ sudo apt-get update

$ sudo apt-get upgrade

1.2 安装编译工具

由于是通过源代码安装 , 说以需要安装编译工具.

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

1.3 安装依赖库

由于OpenCV是计算机视觉库,总需要加载一些图像文件( JPEG, PNG, TIFF)。使用下面命令安装一些必要的图像库:

$ sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev

除了图片之外,OpenCV还要处理视频文件。使用下面命令安装一些视频编解码库

sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev

sudo apt-get install libxvidcore-dev libx264-dev

OpenCV的GUI模块highgui依赖Gtk。安装gtk库:

sudo apt-get install libgtk-3-dev

下面安装一些可以提高OpenCV性能的库,如矩阵操作:

sudo apt-get install libatlas-base-dev gfortran

安装Python2和Python3的开发库:

sudo apt-get install python2.7-dev python3.5-dev

PS Ubuntu14.04中含有python2.7 , 如果不想自己的系统环境太复杂,可以选择不去安装python2.7

下载opencv 源代码

目前OpenCV的最新稳定版是3.2 , 可以去opencv官网上下载, 也可以去github总下载最新版本

最好再下载opencv_contrib,

opencvcontrib模块是Opencv 没有经过足够测试的的新功能模块.OpenCV 在发布新的版本之前,首先在opencvcontrib仓库中发布。当模块成熟并获得普及后,便转移到中央OpenCV存储库,并发布新的版本; :)

注意:opencv和opencv_contrib的版本要一致

# 由于我下载的opencv3.2  所以会在github下找到相应的版本

wget https://github.com/opencv/opencv_contrib/archive/3.2.0.tar.gz

tar -zvxf 3.2.0.tar.gz  # 解压以后生成 opencv_contrib-3.2.0

2. 编译OpenCV

切换到opencv 的build 目录 , opencvbuilddirectory

cd   ## 跳转到opencv 目录

mkdir build  ## 创建 opencv_build_directory

cd   ## 切换到 opencv_build_directory 目录

生成编译文件

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=/home/linux/work_space/opencv_contribute/opencv_contrib-3.2.0/modules \

-D PYTHON_EXECUTABLE=/usr/bin/python2.7 -D BUILD_EXAMPLES=ON ..

make -j    #NUM 自己设定  我设置的是80

ps: 我这里opencvcontrib 的目录是/home/linux/workspace/opencvcontribute/opencvcontrib-3.2.0/ ; 所以参数写成 -D OPENCVEXTRAMODULESPATH=/home/linux/workspace/opencvcontribute/opencvcontrib-3.2.0/modules

最后的 ..  是由于build 目录在openCV里面, 我想编译build 外面的文件,所以要用相对路径 .. 


如果是MacOS  可以采用以下方式编译:

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

-D PYTHON2_PACKAGES_PATH=/usr/local/lib/python2.7/site-packages \

-D PYTHON2_LIBRARY=/Library/Frameworks/Python.framework/Versions/2.7/bin \

-D PYTHON2_INCLUDE_DIR=/Library/Frameworks/Python.framework/Headers \

-D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON \

-D BUILD_EXAMPLES=ON \

-D OPENCV_EXTRA_MODULES_PATH=/Users/lee/workspace/opencv_contrib-3.2.0/modules ..


参数说明:

There are somevery importantoptions we are supplying to CMake here, so let’s break them down:

CMAKE_BUILD_TYPE: This option indicates that we are building a release binary of OpenCV.

CMAKE_INSTALL_PREFIX: The base directory where OpenCV will be installed.

PYTHON2_PACKAGES_PATH: Theexplicitpath to where oursite-packagesdirectory lives in ourcvvirtual environment.

PYTHON2_LIBRARY: Path to our Hombrew installation of Python.

PYTHON2_INCLUDE_DIR: The path to our Python header files for compilation.

INSTALL_C_EXAMPLES: Indicate that we want to install the C/C++ examples after compilation.

INSTALL_PYTHON_EXAMPLES: Indicate that we want to install the Python examples after complication.

BUILD_EXAMPLES: A flag that determines whether or not the included OpenCV examples will be compiled or not.

OPENCV_EXTRA_MODULES_PATH:This option is extremely important— here we supply the path to theopencv_contribrepo that we pulled down earlier, indicating that OpenCV should compile the extra modules as well.



3 安装

make install #  安装

3.1 Mac OS

PS: 如果你是MacOS 那么还需要手动的添加cv2的相关文件到python 中;

我这里提供两种方式:

如果使用brew 安装的, (安装步骤详见 )仅需如此:

查看有没有这个目录   /usr/local/Cellar/opencv/2.4.10/

cd /Library/Python/2.7/site-packages/

ln -s /usr/local/Cellar/opencv/2.4.13.2/lib/python2.7/site-packages/cv.py cv.py

ln -s /usr/local/Cellar/opencv/2.4.13.2/lib/python2.7/site-packages/cv2.so cv2.so




如果是安装以上的源码方式在本地编译安装的情况:


sudo ln -s /usr/local/Cellar/opencv/2.4.13.2/lib/python2.7/site-packages/cv2.so
/Library/Python/2.7/site-packages/cv2.so

 即可


 




4 参考文献

在mac上安装opencv 与python 

ubuntu opencv3.1

opencv-3-0-trouble-with-installation

你可能感兴趣的:(opencv3.2 安装说明书)