1.准备工作
编译环境安装:
$ sudo apt-get install build-essential
必需包安装:
$ 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 libtiff-dev libjasper-dev libdc1394-22-dev
2.下载opencv
去opencv的github下载源码到~/
$ cd ~/
$ wget https://github.com/opencv/opencv/archive/3.2.0.zip
$ unzip 3.2.0.zip
$ rm 3.2.0.zip
$ wget https://github.com/opencv/opencv_contrib/archive/3.2.0.zip
$ unzip 3.2.0.zip
$ rm 3.2.0.zip
此时目录下应有如下两个文件夹:
opencv-3.2.0 opencv_contrib-3.2.0
也可以选择其他稳定版本:
3.编译安装
创建编译目录
$ cd opencv-3.2.0/
$ mkdir build/
$ cd build
生成cmake编译配置:
$ cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules ..
编译
$ make -j4 # runs 4 jobs in parallel
安装
$ sudo make install
4. 安装成功
c/c++库安装成功
查看lib/目录下是否有相关的库文件
$ ls /usr/local/lib/ | grep opencv
查看include/目录下是否有opencv和opencv2文件夹
$ ls /usr/local/include/ | grep opencv
python接口是否导入
查看一下python的import路径
$ python -c "import sys; print sys.path"
去相应的dist-packages目录或者site-packages目录下看看有没有cv2.so, 如果有则说明成功。
在python中
import cv2