参考地址:
http://www.cnblogs.com/arkenstone/p/6490017.html
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 # 处理图像所需的包
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev # 处理视频所需的包
$ sudo apt-get install libatlas-base-dev gfortran # 优化opencv功能
$ sudo apt-get install ffmpeg
2.下载opencv(可以用迅雷下载后复制到虚拟机比较快,复制后要解压出来)
$ wget https://github.com/opencv/opencv/archive/3.2.0.zip # 从github上直接下载或者clone也可
$ wget https://github.com/opencv/opencv_contrib/archive/3.2.0.zip
3.配置编译opencv
$ cd opencv-3.2.0
$ mkdir build $ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/home/fanzong/anaconda2/envs/tensorflow \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules \
-D PYTHON_EXCUTABLE=/home/fanzong/anaconda2/envs/tensorflow/bin/python \
-D WITH_TBB=ON \ -D WITH_V4L=ON \
-D WITH_QT=ON \ # 如果qt未安装可以删去此行;若因为未正确安装qt导致的Qt5Gui报错,可将build内文件全部删除后重新cmake,具体可以参考[这里](http://stackoverflow.com/questions/17420739/opencv-2-4-5-and-qt5-error-s)
-D WITH_GTK=ON \
-D WITH_OPENGL=ON \
-D BUILD_EXAMPLES=ON .. # cmake命令的使用方式:cmake [<some optional parameters>] <path to the OpenCV source directory>。如果命令报错的话可以试着把-D后面的空格去掉在执行一次。
$ make -j4 $ sudo make install
$ sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
$ sudo ldconfig
CMAKE_INSTALL_PREFIX:查看命令 python -c "import sys; print sys.executable"
PYTHON_EXCUTABLE:查看命令 python -c "import sys; print sys.prefix"
OPENCV_EXTRA_MODULES_PATH:下载后解压的路径里面找
Ubuntu下关于安装opencv3.x时一直downloading protobuf-cpp-3.1的问题:
http://download.csdn.net/download/specialshoot/9753560
4.完成安装并测试
安装完成以后,重启下机器。编译之后应该会在CMAKE_INSTALL_PREFIX/lib/python2.7/dist-packages/目录下找到cv2.so。打开python console,检测opencv版本python -c "import cv2; print cv2.__version__"
。如果正确安装的话则会输出3.2.0。