$ 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 liblapacke-dev
$ sudo apt-get install libxvidcore-dev libx264-dev # 处理视频所需的包
$ sudo apt-get install libatlas-base-dev gfortran # 优化opencv功能
$ sudo apt-get install ffmpeg
这里需要下载opencv和opencv_contrib,这是因为opencv3以后SIFT和SURF之类的属性被移到了contrib中,。
$ 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 \ # 1
-D WITH_GTK=ON \
-D WITH_OPENGL=ON \
-D BUILD_EXAMPLES=ON .. # cmake命令的使用方式:cmake [] 。如果命令报错的话可以试着把-D后面的空格去掉在执行一次。
$ make -j4
$ sudo make install
$ sudo /bin/bash -c 'echo "/home/fanzong/anaconda2/envs/tensorflow/lib" > /etc/ld.so.conf.d/opencv.conf'
$ sudo ldconfig
cmake 时遇见的错误及解决方式:
1.opencv CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the Cmake files;
CUDA_nppi_LIBRARY(ADVANCED)
解决:参考:http://blog.csdn.net/u014613745/article/details/78310916
解决方案如下:
1).找到FindCUDA.cmake文件
找到 find_cuda_helper_libs(nppi)
改为2).找到行set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}") 改为
3).找到行unset(CUDA_nppi_LIBRARY CACHE)
改为
修改以下几行
...
set(__cuda_arch_ptx "")
if(CUDA_GENERATION STREQUAL "Fermi")
set(__cuda_arch_bin "2.0")
elseif(CUDA_GENERATION STREQUAL "Kepler")
set(__cuda_arch_bin "3.0 3.5 3.7")
...
改为
...
set(__cuda_arch_ptx "")
if(CUDA_GENERATION STREQUAL "Kepler")
set(__cuda_arch_bin "3.0 3.5 3.7")
elseif(CUDA_GENERATION STREQUAL "Maxwell")
set(__cuda_arch_bin "5.0 5.2")
...
5).cuda9中有一个单独的halffloat(cuda_fp16.h)头文件,也应该被包括在opencv的目录里
将头文件cuda_fp16.h添加至 opencv\modules\cudev\include\opencv2\cudev\common.hpp
即在common.hpp中添加
#include
重新生成即可
2. 每次重新生成 要清除build中的内容 要清除build中的内容 要清除build中的内容